现在的位置: 首页shell>正文
FreeBSD下shell监控一个进程是否存在 [原创]
2012年02月24日 shell FreeBSD下shell监控一个进程是否存在 [原创]已关闭评论 ⁄ 被围观 10,817 次+

由于之前的一个系统要使用队列服务(httpsqs),所以写了一个php脚本定期处理队列数据写入数据库,而这个php脚本是挂在后台循环运行的。一直运行的很好,不知道最近怎么回事,老是不定时的挂掉自动退出,目前原因不明。于是就写了一个shell脚本暂时来监视这个进程,发现进程不在时重新启动这个php脚本,并记录日志,方便查看。代码如下:

  1. #!/bin/sh   
  2.   
  3. while true  
  4. do  
  5.     if ps aux | grep -v grep | grep getsqs.php >/dev/null 2>&1  
  6.     then   
  7.         echo "getsqs.php is run properly!" >>/data/soft/httpsqs/log/getsqs_ok.log   
  8.     else  
  9.         /data/soft/php/bin/php /data/www/www.92csz.com/runscript/getsqs.php &   
  10.         echo "getsqs.php the process does not exist!" >> /data/soft/httpsqs/log/getsqs_err.log   
  11.     fi   
  12. sleep 30  
  13. done  
本文地址:http://www.92csz.com/32/1068.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog
 

抱歉!评论已关闭.