日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
定時(shí)檢查進(jìn)程存在情況
用shell腳本實(shí)現(xiàn)每隔30s檢查httpd進(jìn)程存在與否,httpd存在時(shí)輸出0,不存在輸出1.

方法一:

單條命令實(shí)現(xiàn)
cat apache.sh
#! /bin/bash
while true
do
ps -ef | grep http | grep -v grep > /dev/null  && echo 0 || echo 1
sleep 30
done

while true為真,一直執(zhí)行do循環(huán)。
# ps -ef | grep http ,過(guò)濾出http進(jìn)程
輸出結(jié)果:
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,過(guò)濾ps -ef |grep http本身。
輸出結(jié)果:
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,輸出到空設(shè)備文件。

# ps -ef | grep http | grep -v grep > /dev/null  && echo 0 || echo 1
邏輯與:&&,邏輯或:||。"ps -ef | grep http | grep -v grep > /dev/null"為真時(shí)執(zhí)行echo 0,否則執(zhí)行echo 1.

方法二:
cat apache.sh
while true
httpnum=`ps -ef | grep http | grep -v grep| wc -l`
do
    if [ $httpnum -gt 0 ]
    then 
	echo 0
    else
	echo 1
    fi
sleep 30
done

方案二摘自老男孩博客http://oldboy.blog.51cto.com/2561410/577227,里面有詳細(xì)介紹。

本文名稱(chēng):定時(shí)檢查進(jìn)程存在情況
文章出自:http://www.dlmjj.cn/article/jeiiji.html