Openwrt ash script to check connectivity of router and restart network service if two successive checks (within 5 min) fail.
- Copy the "connectivity_check.sh" file to home directory of root (e.g. /root/)
- Run "crontab -e" as root
- Add below entry, */5 * * * * ping -c1 -q 1.1.1.1 >/dev/null 2>&1 || sh /root/connectivity_check.sh
- Above entry in cron will make a silent ping. If ping fails, it will run the script to check whether another failure occured within last 5 min.
- If this is first failure within last 5 min, the script will save the timestamp in a temporary file to compare during next failure.
- If this is second failure within last 5 min, the script will restart the network service.
- If you want router to reboot on successive failure, change "/etc/init.d/network restart" to "/sbin/reboot" in "connectivity_check.sh" file.