小編給大家分享一下shell腳本shell腳本實現監控某個進程意外停止后拉起進程,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
要監護的進程啟動腳本:實現腳本寫入crontab定時任務
#!/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
以上是“shell腳本shell腳本實現監控某個進程意外停止后拉起進程”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。