I had this script running some time ago in my wifi router (which was running TomatoUSB, a Linux-based firmware available for some Broadcom-based ethernet routers).
#!/bin/sh while [ 1 ]; do nslookup google.com if [ $? -ne 0 ]; then sleep 2 ping -W 2 -c 1 220.127.116.11 if [ $? -ne 0 ]; then (sleep 1; echo admin; sleep 1; echo 1234; sleep 2; echo "reboot"; sleep 3; echo "exit" ) | telnet 192.168.1.1 sleep 300 fi fi sleep 300 done
The script tries to resolve
google.com. If that fails, attempts to ping the Google DNS (
18.104.22.168). If this fails too, tries to connect to
1234 as user/password and sends the
reboot command. The same checks are done every 300 seconds (or 600 if the router has been rebooted). The code above worked on the ADSL routers provided by Telefónica and Jazztel in Spain some time ago.
A good thing of this script is that does not depend on
expect command; and is compatible with busybox if compiled with