DrayTek UK Users' Community Forum

Help, Advice and Solutions from DrayTek Users

Automated Reboots...

  • paul_1011
  • Topic Author
  • Offline
  • New Member
  • New Member
More
26 Jan 2005 15:28 #21436 by paul_1011
Automated Reboots... was created by paul_1011
I had setup a 17 site LAN-LAN link comprising of 16 sites with a single Draytek 2600+ and a head office with 2x2600+

Each of the head office routers had 8 of the remote sites connecting. Although this worked well sometimes the routers would crash and require a physcial reboot. I discovered that if the routers were rebooted then they would work fine. I therefore set about finding a way to reboot them automatically and here it is!

First off this will require a unix variant of some kind with the "expect" package installed(can be got for almost all unix variants). I am guessing that this could be run using cygwin on a windows installation as well.

3 Files are required.

draytekreboot.exp
dreytekreboot.sh
routerlist

Contents of draytekreboot.exp:.......

#!/usr/bin/expect -f

set ipaddy [lindex $argv 0]

set force_conservative 1 ;
;
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

set timeout -1
spawn telnet $ipaddy
match_max 100000
expect "\rPassword: "
send -- "\r"
expect -exact "\r> "
send -- "sys reboot\r"
expect eof

contents of draytekreboot.sh...........

for x in `cat /pathtofiles/routerlist`
do
/pathtofiles/draytekreboot.exp $x
done

"routerlist" simply contains a list of IP addresses of routers that you wish to reboot. With a line break between each one. e.g.

192.168.1.254
192.168.2.254
192.168.3.254

It is clear from the above that this script expects an empty password on the router, it could be easily modified though to pass a varible through which contained the password for each router that needs to be rebooted.

I have just finished testing the script and had it reboot 35 routers in a row. So it would seem to work.

Then the script simply needs to be automated via cron or whatever method you would normally use. I am having the routers rebooted at 6:30am each morning.

Hope this is useful to someone!

Please Log in or Create an account to join the conversation.

More
19 Sep 2005 11:14 #27063 by hamways
Replied by hamways on topic Windows Automatic Reboot Batch File
Hello All,

Wondered if this may help any of the multitude out there who have problems with VPN connections going down and failing to re-establish themselves.

The following batch file works provided you are logged on to your desktop, not if you are logged on but at the logon screen in XP.
Just change the 192.168.xxx.xxx to the ip of your router and xxxPASSWORDxxx to your routers password.


@ECHO OFF



:: Try to open VPN to Router to reboot
PING 192.168.xxx.xxx


:: Create SendKeys script
ECHO.set sh=Wscript.CreateObject("Wscript.Shell")>_TEMP.VBS

:: Send Host Name
ECHO.sh.SendKeys "o 192.168.xxx.xxx" >>_TEMP.VBS
ECHO.Wscript.Sleep 1000 >>_TEMP.VBS


ECHO.sh.SendKeys "{ENTER}" >>_TEMP.vbs
ECHO.Wscript.Sleep 1000 >>_TEMP.vbs



ECHO.sh.SendKeys "xxxPASSWORDxxx" >>_TEMP.VBS
ECHO.Wscript.Sleep 1000 >>_TEMP.VBS


ECHO.sh.SendKeys "{ENTER}" >>_TEMP.vbs
ECHO.Wscript.Sleep 1000 >>_TEMP.vbs


ECHO.sh.SendKeys "sys reboot" >>_TEMP.VBS
ECHO.Wscript.Sleep 1000 >>_TEMP.VBS


ECHO.sh.SendKeys "{ENTER}" >>_TEMP.vbs
ECHO.Wscript.Sleep 1000 >>_TEMP.vbs

ECHO.sh.SendKeys "{ENTER}" >>_TEMP.vbs
ECHO.Wscript.Sleep 1000 >>_TEMP.vbs


ECHO.sh.SendKeys "q" >>_TEMP.VBS
ECHO.Wscript.Sleep 1000 >>_TEMP.VBS


ECHO.sh.SendKeys "{ENTER}" >>_TEMP.vbs
ECHO.Wscript.Sleep 1000 >>_TEMP.vbs

:: Open a telnet window - it will be the window with focus
start /I telnet.EXE


:: Run the script to send keys to telnet window
cscript//nologo _TEMP.VBS

:: Clear away workfile
DEL _TEMP.VBS

EXIT

Copy from @ECHO OFF to EXIT and paste to notepad and save reboot.bat

All you do now is create a scheduled task and point it to reboot.bat

Hope this is useful to someone.
If anyone has any ideas on how to get it to work from the logon screen I would be grateful, I don't like leaving my PC at the desktop in our openplan office!!

Please Log in or Create an account to join the conversation.

More
02 Oct 2005 13:00 #27400 by rmccardal
Replied by rmccardal on topic Automated Reboots...
Could these be made conditional ?

Please Log in or Create an account to join the conversation.

More
05 Oct 2005 17:22 #27501 by telis
Replied by telis on topic Automated Reboots...
Hamways.. that's a brilliant script.. nice one..

Have you tried scheduling it?

Please Log in or Create an account to join the conversation.

More
10 Feb 2006 10:55 #30801 by ajsmith9870
Replied by ajsmith9870 on topic Very useful - thanks
This script is just what I needed, I manage various Draytek routers and have one 2600plus that seems to drop VPN connections on a regular basis, a reboot always cures the problem. Being able to schedule the reboot saves me a lot of hassle.

Thank you :)

Anthony Smith

Please Log in or Create an account to join the conversation.

More
10 Feb 2006 18:44 #30819 by kippy
Replied by kippy on topic Automated Reboots...
I'll probably get shot to pieces for this, and I'm a programmer too, but...

a simple timer switch inline with the mains plug works wonders!

<runs for cover>

:-)

Please Log in or Create an account to join the conversation.

Moderators: ChrisSami