liunx 程序监控是否正常

#!/bin/sh
while true
do
MYDATE=$(date +"%Y-%m-%d %H:%M:%S")
echo "$MYDATE" >> checkhzzm.log
ps -ef | grep "hzzm.jar"| grep -v "grep" >>checkhzzm.log
if [ "$?" -eq 1 ]     #上一条命令返回值0成功,1失败
then
    cd hzzm
    ./start.sh    #要运行的应用程序、脚本等
    echo "process has been restarted!" >>checkhzzm.log
else
    echo "process already started!" >>checkhzzm.log
fi
  sleep 30
 done

 上面是示例,百度抄来的

 

 

 -------------------------------------------------------------------------------------------

# ./check.sh &                    #永真程序,&后台执行 

#!/bin/sh

while true; do
MYDATE=$(date +"%Y-%m-%d %H:%M:%S")
echo "$MYDATE" >> /usr/local/data-integration/kettle_all/logs/kettle.log
ps -ef | grep "./pan.sh" | grep -v "grep" >> /usr/local/data-integration/kettle_all/logs/kettle.log
if [ "$?" -eq 1 ]; then
cd /usr/local/data-integration
./pan.sh -file=./kettle_all/WINDTOYX/DataIncrement/YX_KFK_CONSUMER.ktr -level=Debug -logfile=./logs/YX_KFK_CONSUMER_`date +%F`.log
echo "process has been restarted!" >> /usr/local/data-integration/kettle_all/logs/kettle.log
else
echo "process already started!" >> /usr/local/data-integration/kettle_all/logs/kettle.log
fi
sleep 30
done

ps:
"$?" -eq 1 #上一条命令返回值0成功,1失败
\ 连接符
&& 当上面命令执行成功后,再执行后面的
sleep 30 休眠30秒

       

参考网址:

https://www.cnblogs.com/qmfsun/p/6549799.html

posted @ 2021-11-09 14:56  yongqi-911  阅读(27)  评论(0编辑  收藏  举报