Hello,
I've been using an expect script to disconnect my
router for a very long time. I did a search, some expect scripts to reboot the router have been posted previously, as does the blog post referenced in this thread. The reason I'm posting my own script here is that I use a different method to reset the connection. Since all we really want is to reset the Router-ISP PPP link, my script does only that. Other scripts I've seen all telnet to the router and then reboot it, which of course works, but is unnecessary, and the whole process takes some time. The script I'm using just kills the running ppp daemon, and the connection disconnects and is back up, all within 3 seconds, so it is much more efficient.
Just edit the script below according to your needs (you must change the field), save it to a file (I call mine dsl_reconnect) and give it execute permissions. I run it as a cron job every morning to disconnect before the free night period is up.
Code:
#!/usr/bin/expect -fset timeout 5spawn telnet 192.168.1.1match_max 100000expect -exact "Trying 192.168.1.1...\rConnected to dsl.\rEscape character is '^\]'.\r\rBusyBox on (none) login: "send -- "admin\r"expect -exact "admin\rPassword: "send -- "\r"expect -exact "\r\r\rBusyBox v0.61.pre (2005.05.30-08:31+0000) Built-in shell (ash)\rEnter 'help' for a list of built-in commands.\r\r# "send -- "kill `cat /var/run/ppp0.pid`\r"expect -exact "kill `cat /var/run/ppp0.pid`\r# "send -- ""expect eof