Page 1 of 1

Expect script equivalent on RouterOS

Posted: Thu Jun 27, 2013 3:01 pm
by ElNecio
Hi all,

Is anyone aware of an equivalent to the linux expect command that can be used from routerOS?

What I am trying to achieve is to be able to use a script on an RB750 to monitor reachability to the internet, then if it detects an issue it automatically logs onto my aDSL router and issues the reboot command.

The problem is that the aDSL router only support telnet, so the script will have to issue a series of commands such as:

telnet 1.2.3.4 (This would connect to the device)
thedevicepassword (When promepted for the password it would send this Or just send it anyway after a few seconds)
set reboot (When it receives the command prompt from the device send the reboot command. Or just send it after a few seconds)

In Unix you would use the expect command to achieve this, I am struggling to script this in routerOS.

Can anyone be so kind as to help?

Thanks in advance.

Re: Expect script equivalent on RouterOS

Posted: Thu Jun 27, 2013 5:29 pm
by boen_robot
On the one hand, there is a "telnet" command at "/system telnet", but then again, I see it can't accept a command as an argument, i.e. you must operate it manually, which defeats the point.

One possible workaround is for you to have a separate (3rd) device within the network, and notify it instead of the ADSL router (e.g. using SSH or HTTP). That other device would connect to the ADSL router (over your MT router) using whatever means you have available there (e.g. a custom CLI program that you run with the "/system ssh" command) and reboot it.

Re: Expect script equivalent on RouterOS

Posted: Thu Jul 11, 2013 8:31 am
by omega-00
The only alternative I could offer is, depending on the security of the ADSL modem you could go find the link that is called to reboot it and use the fetch command to tag this.

For example if your ADSL modem is 192.168.1.1 and the username and password are admin/admin and the reset link is /reboot.cgi?submit=yes you would run something like this

ros code

/tool fetch url=http://admin:admin@192.168.1.1/reboot.cgi?submit=yes
This largely depends on how basic the modem is though; some won't accept get requests in place of posts and others would require a login cookie or something rather than the http basic auth.

Re: Expect script equivalent on RouterOS

Posted: Thu Jul 11, 2013 5:08 pm
by ElNecio
The only alternative I could offer is, depending on the security of the ADSL modem you could go find the link that is called to reboot it and use the fetch command to tag this.

For example if your ADSL modem is 192.168.1.1 and the username and password are admin/admin and the reset link is /reboot.cgi?submit=yes you would run something like this

ros code

/tool fetch url=http://admin:admin@192.168.1.1/reboot.cgi?submit=yes
This largely depends on how basic the modem is though; some won't accept get requests in place of posts and others would require a login cookie or something rather than the http basic auth.

Thanks Omega-00, I will give it a try and let you know the outcome.