Non-interactive router reboot HOWTO

7 04 2009

Hi everyone!

I’ve recently been having trouble with a router getting all bunged up due to the high levels of data passing through it. Invariably, I come in in the morning and we’ve lost access to the Internet from some of our stations until I’ve rebooted it. While I’m in the process of building a routing box for the network, I wanted to know if I could automagically have the router reboot itself well before anyone would be wanting access.

As with almost EVERYTHING Linux oriented, the answer is OF COURSE I CAN!

There’s a nifty little utility within Linux called expect. It comes as standard with Slackware, so no installation needed for me. It allows pre-programmed non-interactive access to normally interactive shells. The script I’ve written looks like this:

#!/usr/bin/expect -f
set address [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set routercmd [lindex $argv 3]
spawn telnet $address
expect "Login:"
send -- "$username\r"
expect "Password:"
send -- "$password\r"
# This command gets us out of the default menu and into a shell
expect "> "
send -- "sh\r"
expect "# "
send -- "$routercmd\r"
send -- "^D"
send -- "^D"

As you can see, expect is used as the script handler with the -f flag, which would usually point to a script file to be run.

The script really is incredibly simple…

It takes 4 arguments in this order:
address – The router’s IP,
username – The router’s admin username
password – The router’s admin password
routercmd – The command which you wish to run

In my case, I’ve set up a cron job to run daily at 4.40am (the default for cron.daily) which runs the command /usr/local/bin/routercommand.exp **username** **password** reboot. I am yet to see whether 4.40am is suitable, but it’s a step in the right direction!

Anyway, I hope this has been of interest or maybe even use!


UPDATE – 09/04/09

This has completely fixed our problems with the router. We have seen flawless behaviour since. Whoo! Now if I could only get Smoothwall doing PPPoA with the router in bridge mode! Any ideas would be very helpful!


UPDATE – 24/04/09

It seems that all of these modem/routers which claim to fully support bridge mode are at best exaggerating. The best results it is apparent that you can expect is intermittency, which is TOTALLY USELESS in a production environment. The way forward is using a true PPPoA to PPPoE bridge modem. I’m using a Draytek Vigor 110, because by all accounts it ACTUALLY WORKS (shock, horror!).

Anyway… Just thought I’d feed you all that useful little nugget of knowledge. Hopefully I’ve saved even one person from losing sleep over it.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: