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









第一种方法:crontab定时任务

#!/bin/sh cd /opt/java2/python/ data=https://www.it610.com/article/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='https://www.it610.com/opt/software/mongodb/conf/master.conf' while [ 1 ] dops -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



    推荐阅读