我写的*
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
这。。。唉
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