加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell脚本实现监控某个进程意外停止后拉起进程

发布时间:2020-12-15 16:22:36 所属栏目:安全 来源:网络整理
导读:要监护的进程启动脚本:实现脚本写入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 st

要监护的进程启动脚本:实现脚本写入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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读