我寫的狗屎tomcat
ps aux |grep tomcat_9090_uba |grep -v grep &>/dev/null if [ $? -ne 0 ];then sh /home/tomcat_9090_uba/bin/startup.sh &>/dev/null echo "tomcat9090 start" else ps aux |grep tomcat_9090_uba --color=auto |grep -v grep |awk '{print $2}' |xargs kill -9 && echo "tomcat9090 online" sh /tmp/duidui.sh fi
這。。。唉ide
ps aux |grep -v grep | grep tomcat_9090_uba &>/dev/null # 若是pid不存在,$?爲非零,即直接重啓 if [ $? -ne 0 ];then echo "tomcat9090 is not running" sh /home/tomcat_9090_uba/bin/startup.sh &>/dev/null pid=`ps aux |grep -v grep |grep tomcat_9090_uba | awk '{print $2}'` echo "start tomcat9090 successfully, the pid is $pid" # 若是pid存在,先kill掉,而後再重啓 else pid=`ps aux |grep -v grep |grep tomcat_9090_uba | awk '{print $2}'` echo "tomcat is running, the pid is $pid" echo "Prepare to force restart tomcat_9090_uba" # 殺掉tomcat kill -9 $pid sleep 2 ps aux |grep -v grep | grep tomcat_9090_uba &>/dev/null if [ $? -ne 0 ];then echo "tomcat_9090_uba is killed" fi # 開始從新啓動tomcat echo "start tomcat9090" sh /home/tomcat_9090_uba/bin/startup.sh &>/dev/null # 檢查是否存在存在進程 ps aux |grep -v grep | grep tomcat_9090_uba &>/dev/null if [ $? -eq 0 ];then # 獲取重啓以後的pid號 pid=`ps aux |grep -v grep |grep tomcat_9090_uba | awk '{print $2}'` echo "restart tomcat9090 successfully, the pid is $pid" fi sh /tmp/duidui.sh fi