I have an Actiontec linux-based modem/router. The default configuration for this router saves the last fifty-so host names that anyone on your network looked up. This is cool but not something that I normally use or prefer to have. So I looked up instructions on disabling this feature on this site. The only problem was that since /var is mapped to the RAM, my changes would get reset every time I restarted the modem. Me being the type of person that I am, had to come up with a way to automate this.

The router uses BusyBox shell and allows you to telnet in. First I tried creating a bash script to automate the task but that didn’t work because telnet was expecting the input from the tty instead of a pipe. So I started exploring my options and found expect. expect is an awesome utility created for exactly this purpose, automating interactive applications. I ended up spending a little bit more time on learning the basic syntax (very few commands), and then went on to write the following expect script. This script telnets to the server, deletes the /var/tmp/log_web_activity and links it to /dev/'.

#!/usr/bin/expect -f
spawn telnet
expect "login:"
send "admin\n"
expect "Password: "
expect "# "
send "cd /var/tmp;ls -ld log_web_activity\n"
expect "# "
send "rm log_web_activity\n"
expect "# "
send "ln -s /dev/' log_web_activity;ls -ld log_web_activity\n"
expect "# "
send "logout"
puts "\n----- Finished -----"

If you have not explored expect yet then I would definitely suggest spending some time on it. It is a pretty good tool to have in your arsenal.

Back to blog...