#!/bin/bash
ip=127.0.0.1
while true
do
ping -c1 $ip>/dev/null 2>/dev/null
if [ $? == "0" ];then
echo "`date "+%Y-%m-%d %H:%M:%S "`$ip is up">>a.log
fi
sleep 1
done
写一个工具,对 127.0.0.1 持续监控,当网络断开时,记录时间信息、状态信息到/tmp/a.log
#!/bin/bash
ip=192.168.1.133
while true
do
#ping -c10 $ip>/dev/null 2>/dev/null
NUM=`ping -c1 $ip | grep -i Unreachable | wc -l`
if [ $NUM == "1" ];then
echo "`date "+%Y-%m-%d %H:%M:%S "`$ip is down">>/tmp/a.log
else
echo "`date "+%Y-%m-%d %H:%M:%S "`$ip is up"
fi
sleep 1
done