功能:1:ping所有网内机器的IP地址,如果不通,发送报警
2:检测网内所有机器的服务端口,如果不通,发送报警
#!/bin/bash
##读取IP列表,测试ip的某个端口##
while read ip1
do
ping -c 2 $ip1 >> /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "************************"
echo "ping $ip1 ,ok"
else
echo "************************"
echo "ping $ip1,error,please check"
fi
ipnum=`echo $ip1 |awk -F ‘.‘ ‘{print $4}‘`
echo -e ---------------------$ipnum
#ip =238 的时候,prot 1521 8089#
#ip=239的时候,port 8081 80#
case $ipnum in
238)
for port1 in 1521 8089
do
nc -vv -w1 -z $ip1 $port1 >> /dev/null 2>&1
if [ $? -eq 0 ];then
echo "$ip1 $port1 OK" >>/dev/null 2>&1
else
echo "$ip1 $port1 err,please check" | mail -s "dg-server" [email protected]
fi
done
;;
239)
for port2 in 80 8081
do
nc -vv -w1 -z $ip1 $port2 >> /dev/null 2>&1
if [ $? -eq 0 ];then
echo "$ip1 $port2 OK" >>/dev/null
else
echo "************************"
echo "$ip1 $port2 err,please check"
fi
done
;;
esac
done<iplist
echo "192.168.16.238\n192.168.16.239" >iplist