shell监控是否可以ping通,telnet通其他机器,记录到mysql中

前端之家收集整理的这篇文章主要介绍了shell监控是否可以ping通,telnet通其他机器,记录到mysql中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/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,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='',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

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章