#!/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=("" "" "" "" "")
IPADDR_ARRAY=("" "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 ""
echo 0 > $COUNT_LOG_FILE
fi
else
case $COUNT_FILE_NUMBER in
0)
echo 1 > $COUNT_LOG_FILE
curl ""
;;
1)
echo 2 > $COUNT_LOG_FILE
curl ""
;;
2)
echo 3 > $COUNT_LOG_FILE
curl ""
;;
*)
;;
esac
fi
let i++
done
##################################################################
rm -rf $MY_PID
根据自己的需要可以变化修改这个脚本检测服务器端口存活报警
阅读(1330) | 评论(0) | 转发(0) |