shell监控是否可以ping通,telnet通其他机器,记录到mysql中
发布时间:2020-12-15 07:15:27 所属栏目:安全 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/bin/bash########author:stefanie zhao#function:ping,telnet,curl Portal IP and bep address####### #get local ip addresslocalip=`/sbin/ifco
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 #!/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 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |