[root@BMS001 opt]# cat /opt/checkIP.sh
#!/bin/bash
DATE=$(date +%Y%m%d)
IP="192.168.50.230"
IP_F="192.168.50.230 192.168.50.245 192.168.72.74 192.168.72.75"
echo "`date '+%Y-%m-%d %H:%M:%S'` 网络状态" >>report_${IP}_${DATE}
for i in $IP_F
do
ping -c 2 $i > /dev/null && echo yes"与"${i}"网络正常" >>report_${IP}_${DATE} || echo noÓë${i}"网络不正常" >>eport_${IP}_${DATE}
done
ALL_IP="192.168.40.107 192.168.40.108 192.168.50.240 192.168.40.94 192.168.50.230 192.168.50.245 192.168.50.229 192.168.50.233 192.168.50.155 192.168.72.74 192.168.72.75 192.168.72.72 192.168.72.73 192.168.50.231 192.168.50.239 192.168.50.235 192.168.50.213 192.168.50.243 192.168.50.222 192.168.50.225 192.168.50.216 192.168.50.219"
for i in $ALL_IP; do
ping -c2 $i &>/dev/null
if [ $? = 0 ]; then
echo "`date '+%Y-%m-%d %H:%M:%S'` $i is UP" >> report_${IP}_${DATE}
else
echo "`date '+%Y-%m-%d %H:%M:%S'` $i is DOWN">> report_${IP}_${DATE}
curl "http://172.16.45.128/sendsms?svcid=11011&svcpass=f3547a08dea1f1b14cadc38d849a886a&msgtype=1&smstype=10&phone=XXXXX&msg=$i服务器网络故障,请尽快处理"
curl "http://172.16.45.128/sendsms?svcid=11011&svcpass=f3547a08dea1f1b14cadc38d849a886a&msgtype=1&smstype=10&phone=XXXX&msg=$i服务器网络故障,请尽快处理"
curl "http://172.16.45.128/sendsms?svcid=11011&svcpass=f3547a08dea1f1b14cadc38d849a886a&msgtype=1&smstype=10&phone=XXXXXX&msg=$i 服务器网络异常,请马上处理"
curl "http://172.16.45.128/sendsms?svcid=11011&svcpass=f3547a08dea1f1b14cadc38d849a886a&msgtype=1&smstype=10&phone=XXXXX&msg=$i 服务器网络异常,请马上处理"
fi
done