定时检查进程存在情况

  用shell脚本实现每隔30年代检查httpd进程存在与否,httpd存在时输出0,不存在输出1。      方法一:      单条命令实现   cat  apache.sh   # !/bin/bash   while 真正的   做   ps  -ef  |, grep  http  |, grep  -v  grep 祝辞,/dev/null ,,,, echo  0, | |, echo  1   sleep  30   完成      while 真正的为真,一直执行做循环。   #,ps  -ef  |, grep  http 过滤出http进程   输出结果:   root ,,,,, 7286,,,,, 1,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7288,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7289,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7290,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7291,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7292,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7293,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7294,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7295,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   root ,,,,, 7440,, 4708,, 0, 15:17  pts/0,,,, 00:00:00  grep  http   #,ps  -ef  |, grep  http  |, grep  -v  grep,过滤ps  -ef  | grep  http本身。   输出结果:   root ,,,,, 7286,,,,, 1,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7288,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7289,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7290,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7291,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7292,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7293,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7294,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   nagios ,,, 7295,, 7286,, 0, 15:14  ?,,,,,,,, 00:00:00 /usr/sbin/httpd   #,ps  -ef  |, grep  http  |, grep  -v  grep 祝辞,/dev/null,输出到空设备文件。      #,ps  -ef  |, grep  http  |, grep  -v  grep 祝辞,/dev/null ,,,, echo  0, | |, echo  1   逻辑与:,,,逻辑或:| |。”ps  -ef  |, grep  http  |, grep  -v  grep 祝辞,/dev/null”为真时执行echo  0,否则执行echo  1。      方法二:   cat  apache.sh   while 真正的   httpnum=' ps  -ef  |, grep  http  |, grep  -v  grep |, wc  - l '   做   ,,,if  [, httpnum 美元;-gt  0,)   ,,,then    echo  0   ,,,   echo  1   ,,fi   sleep  30   完成      方案二摘自老男孩博客http://oldboy.blog.51cto.com/2561410/577227,里面有详细介绍。


定时检查进程存在情况