提前把我們要檢查的網絡的ip地址寫入到ip.txt文本中,格式如下:
日後,如有網絡增加地址,可直接寫入此文本中;
檢查腳本如下:
#!/bin/bash
#author: lijinzhu
#this is a check network script.
dt=$(date +%Y%m%d)
[ -f /home/vsftproot/check_${dt}.log ] && echo "Clean up expired file: $(ls /home/vsftproot/check_${dt}.log) success... Start check..." && rm -rf /home/vsftproot/check_${dt}.log
echo "system is checking the network service"
echo "Please wating..."
sleep 2
while read line
do
if ping -w 1 -c 1 $line &>/dev/null; then
echo "$line is up" >> /home/vsftproot/check_${dt}.log
else
echo "$line is down" >> /home/vsftproot/check_${dt}.log
fi
done < /root/ip.txt
echo ""
echo "done....you can see "/home/vsftproot/check_${dt}.log""