您现在的位置是:网站首页> 编程资料编程资料
shell脚本实现监控某个进程意外停止后拉起进程_linux shell_
2023-05-26
389人已围观
简介 shell脚本实现监控某个进程意外停止后拉起进程_linux 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脚本每天对MySQL多个数据库自动备份的讲解_linux shell_
- shell脚本操作mysql数据库删除重复的数据_linux shell_
- shell脚本批量删除es索引的方法_linux shell_
- Shell中的while循环几种使用实例详解_linux shell_
- Linux Shell在目录下使用for循环结合if查找文件的巧用_linux shell_
- Shell脚本判断用户的输入内容_linux shell_
- Shell脚本中使用getopts处理多命令行选项_linux shell_
- Shell脚本从文件中逐行读取内容的几种方法实例_linux shell_
- Shell脚本中管道的几种使用实例讲解_linux shell_
- Shell脚本用for循环遍历参数的方法技巧_linux shell_
