一個簡簡單單檢測http服務狀態的腳本


 

#!/bin/bash
#/root/http_status.sh
#This is a check the httpd service status script
#->這是一個檢測服務器狀態的簡單腳本;
P=$(pgrep http) #->首先定義一個變量;
#->另外一個方法: P=`pgrep httpd`
if [ "$P" =  "" ]  #->首先判斷一下http服務啓動後的進程號是不是爲空,若爲空說明這個服務掛了,那掛了就得從新啓動啊,所以執行下面的內容
        then
        service httpd restart >&2
else #->但是如果不爲空則顯示一下內容
        echo "This service is running......"
        echo "Don't have to do anything."
fi
#echo "30/* * * * * /bin/sh /root/http_status.sh >/dev/nll >&2" >> /var/spool/root #->該腳本放在root家目錄下每30分鐘執行一次探測.
~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章