Linux系统简单进程监控脚本

本文发布时间: 2019-Mar-22
为了保证一个PHP页面在后台运行,写了一个监控脚本,假设程序异常退出,那么可以自动重启。 脚本/usr/local/scripts/receve.sh内容如下:#!/bin/bash#funtion:keep receve.php runningPHP="/usr/local/php5/bin/php"PROGRAM="receve.php"#start dameo$PHP /home/httpd/$PROGRAM >>/usr/local/scripts/phpshell/receve.out &chpid="$!";echo "$chpid" > /usr/local/scripts/phpshell/receve.sidecho "child pid is $chpid"echo "status is $?"while [ 1 ]dowait $chpidexitstatus="$?"echo "child pid=$chpid is gone, $exitstatus" >>/usr/local/scripts/phpshell/receve.php_error.logecho `date` >> /usr/local/scripts/phpshell/receve.php_error.logecho "**************************" >>/usr/local/scripts/phpshell/receve.php_error.logsleep 10$PHP /home/httpd/$PROGRAM >> /usr/local/scripts/phpshell/receve.out &chpid="$!";echo "$chpid" > /usr/local/scripts/phpshell/receve.sidecho "next child pid is $chpid"echo "next status is $?"done另外也需要保证监控脚本正常运行,在每天凌晨自动重启脚本/usr/local/scripts/restart_r.sh,写入crontab: #!/bin/bashecho "" >/tmp/receve_pid.txt/bin/ps ax | /bin/grep "receve.sh" | /bin/grep -v "grep" | /bin/awk '{print $1}' >/tmp/receve_pid.txt /bin/kill -9 `cat /tmp/receve_pid.txt | sort -r` sleep 3 /bin/kill -9 `cat /usr/local/scripts/phpshell/receve.sid | sort -r` rm -rf /usr/local/scripts/phpshell/gold_receve.sid sleep 3 /usr/local/scripts/receve.sh > /dev/null &crontab如下: #restart receve.sh10 00 * * * /usr/local/scripts/restart_r.sh注意:脚本的命名要避免重复,以防把自己给杀了!


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:11pm
栏目列表