小记--------Linux脚本监控进程是否存在,不存在重启

 
 
 1 while true
 2 do
 3 #判断进程是否存在
 4 pid=`ps -ef |grep "gbt32960-server-1.0-SNAPSHOT.jar"|grep -v grep`
 5 if [ $? -ne 0 ];then
 6 cd /opt/cdh/job/LOT
 7 echo "" > gb2960.log
 8 sh gb32960.sh
 9 # 重启进行中
10 timestanp=`date +'%Y-%m-%d %H:%M:%S'`
11 echo "$timestanp -gbt32960-server-1.0-SNAPSHOT.jar 重启中,完成后,等待20s 再次尝试 请查看日志:" >>/opt/cdh/job/LOT/gbt32960-server_restart.log
12 sleep 20
13 else
14 #echo "gbt32960-server一切正常"
15 sleep 20
16 fi
17 done
18  
19  
20  
21  
22 while true
23 do
24 #判断进程是否存在
25 pid=`ps -ef |grep "/opt/cdh/submit/reservation/Thermodynamic-1.0-SNAPSHOT.jar"|grep -v grep`
26 if [ $? -ne 0 ];then
27 cd /opt/cdh/submit/reservation
28 nohup sh start_reservation.sh
29 # 重启进行中
30 timestanp=`date +'%Y-%m-%d %H:%M:%S'`
31 echo "$timestanp -gbt32960-server-1.0-SNAPSHOT.jar 重启中,完成后,等待20s 再次尝试 请查看日志:" 2>&1 >>/opt/cdh/submit/reservation/yarn.log &
32 sleep 20
33 else
34 #echo "reservation-server一切正常"
35 sleep 20
36 fi
37 done 
原文地址:https://www.cnblogs.com/yzqyxq/p/13727399.html