Telnet Scripting Tool for Linux(Ubuntu 7.04)

Expect does it do the job for you?
 
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
 
if u use bridged mode then u dont need any scriptsimple ifdown and ifup command wud suffice
 


I got the code.......

you can use "Crontab" for scheduling tasks

Code:
sudo apt-get install telnet
for installing Telnet

Code:
#!/bin/shhost=192.168.1.1port=23login=passwd=cmd=reboot(echo open ${host} ${port}sleep 1echo ${login}sleep 1echo ${passwd}sleep 1echo ${cmd}sleep 1echo exit) | telnet
Save the file as "Telnet.sh"

Then in the terminal navigate to the location of your Script

then type
Code:
./Telnet.sh
OR

just give the file permissions to execute.....
then open the file and choose to execute the script in terminal.

P.S Enter
Code:
chmod +x /Location of your script/Telnet.sh
for giving root permissions for your file. This helps while using Crontab.
Now your router will reboot...
 
Even without a scripting tool I can give u simply Shell Scripts that can be used to configure multiple TELNETable devices. Plz let me know if u need a sample script.
 

Top