Reboot MTNL DSL-502T router automatically using this script

  • Thread starter Thread starter yesudeep
  • Start date Start date
  • Replies Replies 5
  • Views Views 10,473

yesudeep

Newbie
Messages
13
Location
NA
ISP
MTNL Triband
Greetings,

I've written a tiny script using expect that creates a telnet session
and reboots your router when executed. You can set up a cronjob
(or scheduled task using your favorite OS; I don't use Windows).

There are drawbacks to this script:

1. The passwords and other configuration information are in public view.
2. You need to edit the script to configure it to your needs.
3. You will need expect installed to run it.
4. It's not as robust as it can be.
5. More...

However, it does what it should do pretty cleanly.
A better version written in Python is in the works with lots of bells and whistles.
Hopefully, that will allow administrators with several dozen routers to
reboot all of them at once.

Here's the link:
http://yesudeep.unixpod.com/scripts/rebootrouter/rebootrouter.exp

Please tailor the script to your needs. Please note that this code
is released under the GNU GPL.

Regards,
Yesudeep.

PS: There is more information in my second post below.
 
Could you please post why and how this is better than the converntional telnet reboot? I don't see any significant differnce though. And please post on how to use it, for newbies.
 
Could you please post why and how this is better than the converntional telnet reboot? I don't see any significant differnce though. And please post on how to use it, for newbies.

This *is* a telnet reboot. Expect is a language and tool to write
scripts that interact with terminal sessions. What you do using telnet
manually has simply been expressed as an expect script. It "types"
in all that stuff and "waits" for those prompts just like you would.

The following scripts are canned scripts that work for routers
that have not been manually configured to differ from the defaults.

Python version
http://yesudeep.unixpod.com/scripts/rebootrouter/rebootrouter.py

Expect version
http://yesudeep.unixpod.com/scripts/rebootrouter/rebootrouter.exp

TST version
http://yesudeep.unixpod.com/scripts/rebootrouter/rebootrouter.tst

Macro Scheduler version
http://yesudeep.unixpod.com/scripts/rebootrouter/rebootrouter.mch


Generating the Scripts

You can use

http://yesudeep.unixpod.com/scripts/rebootrouter/gen-rebootrouter.py

to generate all the abovementioned scripts for your configuration.
Using this script you don't need to manually edit the script files yourself.
Just answer the questions it asks you and it will generate the scripts for you.
(This is not the power-user/admin script I spoke about in the first post above.)

Download and install Python from Python Programming Language -- Official Website
Then, to generate the scripts open a terminal window and type this:


Code:
$ python gen-rebootrouter.pyThis program will generate rebootrouter scriptsfor you tailored to your router configuration.Please answer all the questions presented to you.  You can pressthe Enter/Return key on your keyboard without entering a valueto choose the default value (displayed in square brackets).Router IP Address [192.168.1.1]: Router Telnet Port [23]: Router Username [admin]: Router Password [admin]: Script Location [/home/you/Desktop/reboot-router]: Generating Expect script at /home/you/Desktop/rebootrouter.expGenerating Python script at /home/you/Desktop/rebootrouter.pyGenerating Telnet Script Tool script at /home/you/Desktop/rebootrouter.tstGenerating Macro Scheduler script at /home/you/Desktop/rebootrouter.mch$ chmod +x rebootrouter.exp rebootrouter.py$ ./rebootrouter.exp... does the telnet thing to reboot your router ...$ ./rebootrouter.py... does the telnet thing to reboot your router ...

More ways to run the scripts including on Windows:


Code:
C:\> tst10.exe /r:rebootrouter.tst... does the telnet thing to reboot your router for Windows users using TST ...C:\> msched.exe rebootrouter.mch... does the telnet thing to reboot your router for Windows users using Macro Scheduler ...$ expect rebootrouter.exp... does the telnet thing to reboot your router ...$ python rebootrouter.py... does the telnet thing to reboot your router ...

Scheduling the Reboot to Occur Automatically using Cron

You can use any version of the scripts you want to
reboot your router. You stick this command in a scheduled task.
For example, you could set up two tasks, one to run at 8:00 AM and the
other at 12:00 AM, each of which executes this command. Explaining how
to set up a scheduled task on every operating system out there is out of the scope
of this post. You'll need to refer to manuals for your operating system.
If you're using GNU/Linux you can look up tutorials for crontab.
However, I'm providing an example for reference:


Code:
root@hostname:/root# export EDITOR='emacs -nw'root@hostname:/root# crontab -e                   # starts your $EDITOR# minute(0-59) h(0-23)  day-of-month(1-31) month(1-12) day-of-week(0-6)   command0 0,08 * * * /usr/local/bin/rebootrouter.py >> /var/log/rebootrouter.log 2>&1
I've given /usr/local/bin/rebootrouter.py executable permissions.
This will setup a scheduled task to reboot the router using that
script at exactly 08:00 hours and 00:00 hours.

Sample contents of /var/log/rebootrouter.log

Code:
[2007-07-22 02:06:07.342603] Rebooting router at 192.168.1.1[2007-07-22 02:06:55.892977] Rebooting router at 192.168.1.1[2007-07-22 08:00:01.371167] Rebooting router at 192.168.1.1

Using Gnome Schedule to schedule the task

You can use gnome-schedule, for example, if you're not comfortable
with the command line. The screenshots below show the basic and advanced
configuration screens for gnome-schedule.

http://yesudeep.unixpod.com/scripts/rebootrouter/screenshots/basic-schedule.png

http://yesudeep.unixpod.com/scripts/rebootrouter/screenshots/advanced-schedule.png

Conclusion
If you asked me about my pick from the scripts, I'd unflinchingly choose the Python version.
Why? It's the most portable thing out of all those. It works on UNIX, GNU/Linux, Windows, etc.
The only two things you will need are Python (which is a great language for other needs too!)
and pexpect which you can install pretty easily. If you need help, just ask.


Sidenotes:
Running the expect version of the rebootrouter scripts (rebootrouter.exp) requires
installing Expect (Expect - Expect - Home Page).

To run the python version of the rebootrouter script (rebootrouter.py) you will need
pexpect from Pexpect - a Pure Python Expect-like module installed along with Python
(Python Programming Language -- Official Website) on your computer.

On windows you can probably just double click on the rebootrouter.py file and it will
reboot your router.

The TST version of the script requires reading this thread:
https://broadband.forum/mtnl-triband-broadband/1741-finally-trib-nu-solution/#post18114

You might need to synchronize your time with one of several NTP servers on the Internet.
Do NOT set your system time to that of MTNL. That will break too many applications.
Instead set up the scheduler time to one in sync' with the time at one of MTNL's servers.
Here's a list of some NTP servers:

ntp.ubuntu.com
time.nrc.ca (canada)
ntp1.cmc.ec.gc.ca
ntp2.cmc.ec.gc.ca
clock.tricity.wsu.edu
wuarchive.wustl.edu
clock.psu.edu
constellation.ecn.uoknor.edu
gilbreth.ecn.purdue.edu
molecule.ecn.purdue.edu
libra.rice.edu
ntp.cox.smu.edu
louie.udel.edu

Google for more! ;-)


Additional reading:
technobabble: Auto-Rebooting ADSL Routers Using Telnet

Regards,
Yesudeep.
technobabble
 
yeah but what bout linux guys .. that's y i liked the python script...
 


Top