OpenWRT路由器中監控網絡服務并重啟的腳本

1,303次阅读
没有评论

在 /root 下編寫一個 my_watchdog.sh 腳本:

#!/bin/sh
#sleep 100
DATE=`date +%Y-%m-%d-%H:%M:%S`
tries=0
echo — my_watchdog start —
while [[$tries -lt 5]]
do
if /bin/ping -c 1 8.8.8.8 >/dev/null
then
echo — exit —
# echo $DATE OK >>my_watchdog.log
exit 0
fi
tries=$((tries+1))
sleep 10
# echo $DATE tries: $tries >>my_watchdog.log
done

echo $DATE network restart >>my_watchdog.log
/etc/init.d/network restart

#echo $DATE reboot >>my_watchdog.log
#reboot
然後用 crontab - e 來在系統的 crontab 中添加一句,每隔 5 分鐘定時運行這個腳本:

*/5 * * * * sh /root/my_watchdog.sh

0 0,4,8,12,16,20 * * * date -u +”%Y.%m.%d-%H:%M:%S” >/usr/data/time_backup
0,1,11,21,31,41,51 * * * * /usr/bin/set_kernel_timezone >/dev/null 2>&1
0 0,4,8,12,16,20 * * * /tmp/bw_backup/do_bw_backup.sh

正文完
 0
评论(没有评论)
验证码