以前写过个脚本 放在树莓派上自己跑 断网会在 Log 文件夹生成记录:
#!/bin/bash
WGET="/usr/bin/wget"
second=0
for (( ; ; ))
do
$WGET -q --tries=1 --timeout=1
http://www.baidu.com -O /tmp/file.idx &> /dev/null
if [ ! -s /tmp/file.idx ]
then
if [ "$second" -eq "1" ]
then
echo "$(date +"%Y-%m-%d %H:%M:%S "): Disconnected" >> ./Log/network_connection-$(date +"%Y-%m-%d").log
fi
let "second += 1"
else
if [ "$second" -gt "1" ]
then
echo "$(date +"%Y-%m-%d %H:%M:%S "): Reconnected, downtime: $second 's" >> ./Log/network_connection-$(date +"%Y-%m-%d").log
fi
second=0
fi
sleep 1
done