#!/bin/bash ###### # #author:stefanie zhao #function:ping,telnet,curl Portal IP and bep address # ###### #get local ip address localip=`/sbin/ifconfig eth1 | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 1` echo "localip--------$localip" HOST=172.0.0.1 USER=***** PASS=***** #ping telnet target ip #get portal ip address mysql -h$HOST -u$USER -p$PASS dbname -N -e "select id,tip from table where sip='$localip'" | while read a b do echo "=====ip===$a $b" #ping this other ip ret=$(ping -w 2 -c 1 $b | awk -F / 'END{print $5}') echo "-----$ret" if [ "$ret" != "" ];then #telnet this other ip address nagios 多功能监控脚本check_tcp(附件中) telnet=`./check_tcp -H $b -p 6601 -t 5 | grep TCP | awk '{printf $2}'` if [ "$telnet" == "OK" ];then echo "ping---ok$ret" echo "telnet ok" mysql -h$HOST -u$USER -p$PASS dbname -N -e "update table set pingstatus=1 ,pingtime='$ret', telnetstatus=1,checkdate=now() where id=$a" else echo "ping---ok$ret" echo "telnet no" mysql -h$HOST -u$USER -p$PASS dbname -N -e "update table set pingstatus=1 ,pingtime='$ret', telnetstatus=0,checkdate=now() where id=$a" fi else echo "ping---no" mysql -h$HOST -u$USER -p$PASS dbname -N -e "update table set pingstatus=0 ,pingtime='', telnetstatus=0 ,checkdate=now() where id=$a" fi done #curl 站点是否可用 #curl mysql -h$HOST -u$USER -p$PASS dbname -N -e "select id,bepurl from table where sip='$localip'" | while read a b do echo "----------curl $a $b" result=`curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} $b` test=`echo $result` if [[ "$test" = "200" ]] then echo "$b is ok" else echo "$b is no" fi mysql -h$HOST -u$USER -p$PASS dbname -N -e "update table set curlstatus=$test , checkdate=now() where id='$a'" done