DrayTek UK Users' Community Forum

Help, Advice and Solutions from DrayTek Users

Automated Reboots...

More
11 Dec 2007 08:55 #46276 by stoney_sjl
Replied by stoney_sjl on topic Automated Reboots...
A thought for Peppery. A command/batch file can be automated in Windows using the "Scheduled Tasks" application.
Cheers
Simon

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

  • paul_1011
  • Topic Author
  • Offline
  • New Member
  • New Member
More
29 Jan 2008 23:06 #47151 by paul_1011
Replied by paul_1011 on topic Automated Reboots...
I decided to write yet another reboot script, a bit slicker than the original one and can also be conditional based on wether another IP/host is reachable, plus I needed something that works from Windows.

First of all it requires the Toolsack baseline components to be installed from here:

http://www.toolsack.com/download/

The script itself works by passing of parameters, so a typical command line would look like this:

cscript reboot.vbs 86.11.93.131 routerpassword

and a conditional command line would look like this:

cscript reboot.vbs 86.11.93.131 routerpassword 192.168.1.254

The 3rd argument will be tested for a ping response, if none is received then a reboot will be executed. This is useful for testing if a VPN link is down and then using a reboot to establish the connection again.

Here is the code, save it as reboot.vbs:

Code:
set args=wscript.arguments If wscript.arguments.count=2 then IP=args.item(0) Password=args.item(1) call reboot(IP,Password) elseif wscript.arguments.count=3 then IP=args.item(0) Password=args.item(1) TestIP=args.item(2) if ping(TestIP)=False then call reboot(IP,Password) end if else wscript.echo "Invalid number of arguments specified" wscript.echo "Please specify router IP address & password and optional test IP" end if sub reboot(IP, Password) set s = CreateObject("Toolsack.Socket") s.Connect IP, 23 s.Write Password & vbCrLf s.write "sys reboot" & vbcrlf s.write "quit" & vbcrlf end sub Function Ping(strHost) dim objPing, objRetStatus set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _ ("select * from Win32_PingStatus where address = '" & strHost & "'") for each objRetStatus in objPing if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then Ping = False else Ping = True end if next End Function


I am thinking of writing another script which will automatically back up the configs of many routers as well. I will probably post up a finished version on my blog, but this seems to work very well.

I am running it on a schedule to ensure continued VPN connectivity.

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

More
30 Jan 2008 10:41 #47163 by admin
Replied by admin on topic Automated Reboots...
That's rather nice :-) I don't need your actual script but your example gives me all sorts of other dastardly ideas. Thanks.



Forum Administrator

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

More
30 Jan 2008 10:47 #47165 by andybill
Replied by andybill on topic Automated Reboots...
following on from this and going back to my first set of questions:

is there any documentation available on the CLI (not just the command list spreadsheet that;s on draytek.com.au ), e.g. for setting up syslog and SNMP, etc?

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

More
22 Mar 2010 20:11 #61300 by yoshino
Replied by yoshino on topic Cheers!
Nice one Paul!

Just tried out your conditional telnet script and it works like a charm!

Cheers for that! :D

BTW, where can I find your blog?

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

  • paul_1011
  • Topic Author
  • Offline
  • New Member
  • New Member
More
22 Mar 2010 20:16 #61302 by paul_1011
Replied by paul_1011 on topic Automated Reboots...
Glad you are still finding it useful!

blog is at http://www.tachytelic.net

I was thinking of adding this script to the blog actually, I think its quite a neat bit of code.

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

Moderators: ChrisSami