Tomcat启动和停止脚本
#!/bin/bash CATALINA_HOME=/usr/local/apache-tomcat-8.5.56 STARTUP=$CATALINA_HOME/bin/startup.sh SHUTDOWN=$CATALINA_HOME/bin/shutdown.sh function isstart(){ status=`netstat -an | grep 8080 | awk '{print $6}'` if [ $status = 'LISTEN' ];then return 1 else return 2 fi } function startup(){ echo "判断Tomcat状态" isstart s=$? if [ $s -eq 1 ];then echo "Tomcat已经启动,不需要再次启动" else echo "Tomcat没有运行,1s 后启动Tomcat" sleep 1 $STARTUP fi } function shutdown(){ echo "判断Tomcat状态" isstart s=$? if [ $s -eq 2 ];then echo "Tomcat已经关闭,不需要再次关闭" p else echo "Tomcat已在运行,1s 后关闭Tomcat" sleep 1 $SHUTDOWN pidlist=`ps -ef |grep $CATALINA_HOME |grep -v "grep"|awk '{print $2}'` kill -9 $pidlist fi } function restart(){ shutdown startup } case $1 in 'startup') startup ;; 'shutdown') shutdown ;; 'restart') restart ;; *) echo "请输入正确参数 startup / shutdown / restart" esac