#!/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" != "" ]
then
exit 0
fi
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" ]
then
mkdir -p $CHECK_LOG_DIR
fi
if [ ! -d "$COUNT_LOG_DIR" ]
then
mkdir -p $COUNT_LOG_DIR
fi
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" ]
then
echo 0 > $COUNT_LOG_FILE
fi
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" ]
then
if [ "$COUNT_FILE_NUMBER" = "3" ]
then
curl "http://sms.api.bz/fetion.php?username=159555555&password=254605sxz&sendto=1595333333&message=$WEB_MESSAGE_SUCCESS"
echo 0 > $COUNT_LOG_FILE
fi
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
fi
let i++
done
##################################################################
rm -rf $MY_PID
根据自己的需要可以变化修改这个脚本检测服务器端口存活报警
转载于:https://blog.51cto.com/liang3391/456605