监听进程并自动重启(两种方法)





第一种方法:crontab定时任务

#!/bin/sh
cd /opt/java2/python/
data=./Begin
ps -fe|grep $data |grep -v grep
if [ $? -ne 0 ]
then
echo begin `date '+%Y%m%d %H:%S:%M'`
echo "start process....."
sh /opt/java2/python/start.sh
else
	echo "runing....."
fi


第二种方法:死循环 nohup运行

#!/bin/sh
data='/opt/software/mongodb/conf/master.conf'
while [ 1 ]
    do

    ps -fe|grep $data |grep -v grep > master_mongodb_jiance.log
    if [ $? -ne 0 ]
    then
        echo 'mongodb no done...'
        date
        /opt/software/mongodb/bin/mongod -f /opt/software/mongodb/conf/master.conf
    else
        echo "is running"
    fi
    sleep 30
done


你可能感兴趣的:(linux)