用shell脚本监控进程是否存在 不存在则启动的实例

最近发现测试环境里的virgo-tomcat会莫名的自己挂掉,通过ps -ef | grep virgo-tomcat 也查不到进程ID,也看不到错误日志信息。于是想到一个不得已的办法,

写一个脚本来监测virgo-tomcat进程是否存在,如果不存在就启动它。以下是脚本的具体内容:

 1 #!/bin/sh
 2 
 3 while true;do
 4 count=`ps -ef|grep virgo-tomcat|grep -v grep`
 5 if [ "$?" != "0" ];then
 6 echo ">>>>no platform,run it"
 7 ./bin/startup.sh
 8 else
 9 echo ">>>>platform is runing..."
10 fi
11 sleep 10
12 done

 

然后执行nohup sh ./monitorprocess.sh > monitorprocessout.file 2>&1,该命令的作用是让你退出账户之后该进程可以继续运行,并且可以让脚本里echo展示的内容重定向到monitorprocessout.file中,然后用tail -f monitorprocessout.file来实时的看到echo展示的内容,来判断该shell脚本是否已经在后台运行良好

posted @ 2015-02-15 16:43  mark..  阅读(576)  评论(0编辑  收藏  举报