要監(jiān)護的進程啟動腳本:實現(xiàn)腳本寫入crontab定時任務(wù)
#!/usr/bin/env bash # scheduled task at 22:00 everyday script_path=`eval pwd` user_name=`whoami` echo "crontab_script_path:${script_path}" sudo echo "* * * * * cd ${script_path} sh xxx.sh > start_cron.log " >> /var/spool/cron/${user_name}
守護進程腳本:
#!/usr/bin/env bash jd=`ps -ef | grep xxx | grep -v grep | awk -F" " '{print $2}'` dt=`date "+%Y-%m-%d %H:%M:%S"` arr=($jd) len=${#arr[@]} if [ "$len" -lt 4 ] then echo "xxx process's num less than 4, kill it all (time: $dt)" >> xxx.logs sh stop.sh jd="" sleep 10s fi if [ "$jd" = "" ] then echo "xxx exe is restarting (time: $dt)" >> xxx.logs source ~/.bash_profile sh start.sh fi
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接