shell监控是否可以ping通,telnet通其他机器

shell监控是否可以ping通,telnet通其他机器
#!/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

转载于:https://my.oschina.net/stefanzhlg/blog/317350

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值