#!/bin/sh
#################################################
# check remote os service
#
# date:2010-02-26
##################################################
export LANG=en_US.UTF-8
###########################################
# check pid
############################################
MY_PID='/tmp/check.pid'
#妫€鏌id鏂囦歡鏄惁瀛樺湪
if [ -f "$MY_PID" ]
then
#pid鏂囦歡瀛樺湪
PID_NUM=$(cat /tmp/check.pid)
CHECK_PID=$(ps aux | grep $PID_NUM | grep -v grep)
#妫€鏌ヨ繖涓猵id杩涚▼鏄惁瀛樺湪
if [ "$CHECK_PID" != "" ]
exit 0
fi
#鐢熸垚绋嬪簭鑷繁鐨刾id,骞朵繚瀛?
#$$鎸囩殑鏄綋鍓嶇▼搴廝ID
echo $$ > $MY_PID
##################################################################################
ROOT_DIR='/root/monitor'
#IPADDR_ARRAY=("http://www.pk.com" "http://news.pk.com/shtml/20100401/864541.shtml" "http://down.pk.com/xiazai/6661.shtml" "http://xin.1.html" "http://act.2pk.com/spe/10/wow/5years/")
IPADDR_ARRAY=("www.51112pk.com" "p2p.inbel.com")
IPADDR_ARRAY_LEN=${#IPADDR_ARRAY[@]}
#SERVICE_PORT='80'
CHECK_LOG_DIR="$ROOT_DIR/check_log"
COUNT_LOG_DIR="$ROOT_DIR/count_log"
#####################################
#check directory and count file
if [ ! -d "$CHECK_LOG_DIR" ]
mkdir -p $CHECK_LOG_DIR
if [ ! -d "$COUNT_LOG_DIR" ]
mkdir -p $COUNT_LOG_DIR
i=0
while [ $i -lt $IPADDR_ARRAY_LEN ]
do
IPADDR=${IPADDR_ARRAY[$i]}
CHECK_LOG_FILE="$CHECK_LOG_DIR/$IPADDR.log"
COUNT_LOG_FILE="$COUNT_LOG_DIR/$IPADDR.txt"
WEB_MESSAGE_FAILED="$IPADDR--is-not-running"
WEB_MESSAGE_SUCCESS="$IPADDR--is-up-and-runing-fine"
if [ ! -s "$COUNT_LOG_FILE" ]
echo 0 > $COUNT_LOG_FILE
COUNT_FILE_NUMBER=$(cat $COUNT_LOG_FILE)
echo | curl -I $IPADDR > $CHECK_LOG_FILE
#grep "404" $CHECK_LOG_FILE > /dev/null
HTTP_STATUS=$(head -n 1 $CHECK_LOG_FILE | awk '{print $2}')
if [ "$HTTP_STATUS" = "200" ]
if [ "$COUNT_FILE_NUMBER" = "3" ]
curl "http://sms.api.bz/fetion.php?username=159555555&password=254605sxz&sendto=1595333333&message=$WEB_MESSAGE_SUCCESS"
else
case $COUNT_FILE_NUMBER in
0)
echo 1 > $COUNT_LOG_FILE
curl "http://sms.api.bz/fetion.php?username=159522222&password=254605sxz&sendto=1595555557&message=$WEB_MESSAGE_FAILED"
;;
1)
echo 2 > $COUNT_LOG_FILE
curl "http://sms.api.bz/fetion.php?username=1592222&password=254605sxz&sendto=15911111&message=$WEB_MESSAGE_FAILED"
2)
echo 3 > $COUNT_LOG_FILE
curl "http://sms.api.bz/fetion.php?username=15952222&password=254605sxz&sendto=159111111&message=$WEB_MESSAGE_FAILED"
*)
esac
let i++
done
##################################################################
rm -rf $MY_PID
根據自己的需要可以變化修改這個腳本檢測伺服器端口存活報警
'
本文轉自 liang3391 51CTO部落格,原文連結:http://blog.51cto.com/liang3391/456605