CentOS使用脚本监控进程、自动重启、日志记录

CentOS使用脚本监控进程、自动重启、日志记录
#!/bin/sh
file_name="/mnt/nginxmonitor_2.log"
proc_name="nginx"
while true
do
A=`ps -C $proc_name --no-header | wc -l`
if [ $A -eq 0 ];then    
    echo $(date +%F%n%T) "nginx未启动,启动nginx..."
    systemctl start $proc_name
    pid=`ps -ef | grep $proc_name | grep -v grep | awk '{print $2}'`
    echo ${pid}, `date` >> $file_name    
    sleep 10
else
    echo $(date +%F%n%T) "nginx正在运行..."
fi

sleep 5
done

代码如上,可以使用crond服务定时启动。

相关博客:

  1. 对于crontab定时任务不能自动执行的总结

https://www.cnblogs.com/wang3680/p/5383645.html

  1. linux 进程监控和自动重启的简单实现

https://blog.csdn.net/liumangxiong/article/details/7084637

赞赏
Nemo版权所有丨如未注明,均为原创丨本网站采用BY-NC-SA协议进行授权,转载请注明转自:https://nemo.cool/613.html
#
首页      Dev      Linux      CentOS使用脚本监控进程、自动重启、日志记录

Nemo

文章作者

推荐文章

发表回复

textsms
account_circle
email

CentOS使用脚本监控进程、自动重启、日志记录
#!/bin/sh file_name="/mnt/nginxmonitor_2.log" proc_name="nginx" while true do A=`ps -C $proc_name --no-header | wc -l` if [ $A -eq 0 ];then echo $(date +%F%n%T) "ngin…
扫描二维码继续阅读
2020-07-29