I hate my Speedtouch ADSL router. Occasionally it`ll crumple under the weight of some large file transfers and drop the connection to the Internet. It`s a pain in the arse. However, it`s currently not the right time to buy a replacement. I therefore set up a quick cron job to ping a few Internet sites, and if these fail, kick off a script to reboot the router.
The ping part is pretty simple, so go off and research that. For the reboot, it`s some crappy python and “pexpect”, like so:
# apt-get install python-pexpect telnet
# if necessary – or through the package manager of your
child = pexpect.spawn(‘telnet 192.168.1.254′)
child.expect(‘sername : ‘, timeout=5)
child.expect(‘assword : ‘, timeout=5)
child.send (‘system reboot\r\n’)
Where I tripped up was using “sendline” instead of “send” above – watch out for that as you`ll notice \r\n needs to be sent for a newline. pexpect isn`t very elegant, but it makes this sort of scripting very easy.
Have fun. Also, “assword”. Teehee.