脚本监控2个进程有进程死掉重启进程
#!/bin/sh echo "Current DIR is " $PWD while [ 1 ] do serverpid=`ps -ef|grep process1|grep -v grep|awk '{print $2}'` serverpid2=`ps -ef|grep process2|grep -v grep|awk '{print $2}'` if [ "$serverpid" ] && [ "$serverpid2" ] then echo "process1 is running,pid is " $serverpid echo "process2 is running,pid is " $serverpid2 #kill -9 $serverpid elif [ "$serverpid" ] then echo "process1 is running ,pid is ..." $serverpid echo "process2 is down, now starting...." dt=`date +%F` nohup /data/website/process2 2>>/data/socket/$dt"_pa_error.log" 1>>/data/socket/$dt"_pa_access.log" & elif [ "$serverpid2" ] then echo "process2 is running,pid is...." $serverpid2 echo "process1 is down, now starting......" dt=`date +%F` nohup /data/website/process1 2>>/data/socket/$dt"_ad_error.log" 1>>/data/socket/$dt"_ad_access.log" & else echo "process1 is down ,now starting ..." echo "process2 is down, now starting...." dt=`date +%F` nohup /data/website/process2 2>>/data/socket/$dt"_pa_error.log" 1>>/data/socket/$dt"_pa_access.log" & nohup /data/website/process1 2>>/data/socket/$dt"_ad_error.log" 1>>/data/socket/$dt"_ad_access.log" & fi sleep 5 done