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

该脚本是一个自动化监控工具,用于检查本地主机与其他IP的ping、telnet和curl连接。它从数据库获取目标IP,然后进行ping测试,根据返回值更新数据库中的ping状态。接着,脚本尝试telnet连接到指定端口,并更新telnet状态。最后,使用curl检查网站可达性并记录HTTP响应码。此脚本对于网络运维和监控至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值