shell脚本实现监控某个进程意外停止后拉起进程
要监护的进程启动脚本:实现脚本写入crontab定时任务
#!/usr/bin/envbash
#scheduledtaskat22:00everyday
script_path=`evalpwd`
user_name=`whoami`
echo"crontab_script_path:${script_path}"
sudoecho"*****cd${script_path}&&shxxx.sh>start_cron.log">>/var/spool/cron/${user_name}
守护进程脚本:
#!/usr/bin/envbash
jd=`ps-ef|grepxxx|grep-vgrep|awk-F""'{print$2}'`
dt=`date"+%Y-%m-%d%H:%M:%S"`
arr=($jd)
len=${#arr[@]}
if["$len"-lt4]
then
echo"xxxprocess'snumlessthan4,killitall(time:$dt)">>xxx.logs
shstop.sh
jd=""
sleep10s
fi
if["$jd"=""]
then
echo"xxxexeisrestarting(time:$dt)">>xxx.logs
source~/.bash_profile
shstart.sh
fi
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对毛票票的支持。如果你想了解更多相关内容请查看下面相关链接