Applescript to ssh into router and reboot

I'm trying to write an applescript that will ssh into my router and reboot the router. I would like this so that my wife can simply execute an automator file and it will restart the router without her having to unplug the router. I've got the following but it's not logging into the router. Can anyone offer suggestions one what I'm doing wrong. Thanks.


User uploaded file

MacBook Pro, OS X Mountain Lion (10.8.2)

Posted on Oct 21, 2012 1:33 AM

Reply
12 replies

Oct 21, 2012 7:59 AM in response to mac_hk

Is this an 'expect' script?


Or are you trying to send these commands to the router to be executed?


If sending to the router you could put them in a file and then have ssh read the file contents and send it to the router


ssh -options root@192.168.1.1 <file.with.cmds.to.be.executed.on.router


If this is an expect script, have you run this from a regular terminal session?


If you are into blind faith, you could just send the commands you expect to work and not bother looking at what is returned


( sleep 2

echo 12345

sleep 4

echo reboot

sleep 10

send exit

) | ssh root@192.168.1.1


The sleep times are assumes to give the router more than enough time to return the expected prompt. Adjust accordingly.


This is "Rude and Crude", but would it work?

Oct 21, 2012 8:24 AM in response to mac_hk

Thinking a little more on this, ssh would be prompting for the password on the Mac, and not from the router.


Can you create an ssh-keygen key on your Mac, then copy the $HOME/.ssh/*.pub key to the router's ~root/.ssh/authorized_keys file?

If you create a passwordless ssh key (Google it, and you will find instructions), you can most likely then use a command such as


ssh root@192.168.1.1 reboot


or maybe


( echo reboot

sleep 10 # if you have to wait around before disconnecting the session

) | ssh root@192.168.1.1

Oct 22, 2012 5:29 AM in response to mac_hk

Yes, a new router is a very good course of action. I'm running a persistent VPN connection on an ASUS RT-N16 with a Tomato firmware variant using OpenVPN, and it's just not stable for longer than a few days - I'm connecting to a paid VPN service. I believe it has to do with the VPN server's issuance of IP's (Dynamic IP) - I think it somehow causes the Tomato's implementation of OpenVPN to choke when a new IP is assigned. I don't know, these are issues beyond my understanding and I'm tired of rebooting. My thought is to buy something more robust, like a ZyWall USG 50 or a CISCO ASA 5505, something more stable that can handle external hickups.

Oct 24, 2012 2:27 PM in response to mac_hk

You should look into placing your reboot script on the tomato router itself, then ssh in and execute the script rather than doing all that expect magic. google tomato router scripts for info. Also, authorized_keys can be used with the tomato router so no need for a password.

Good luck and it's more fun than buying a new router.

Or even better have a cron script run and test connectivity then execute. This link has some good ideas:


http://www.linksysinfo.org/index.php?threads/tomato-automatic-router-synchroniza tion-using-remote-script-execution.37003/

Oct 24, 2012 6:27 PM in response to mac_hk

Two questions for you:

1) Have you EVER SSHed into this router? Is this router even SSH-able? Most are not for reasons of economy. A router must be running a Linux kernel of some sort, which hardware is more costly to mass produce.


2) Why do you need to reboot it? Any modem-router older than 4 years is already a candidate for the e-waste bin due to increasingly demanding (and nonstandard) network protocols. The need to constantly reboot a modem to connect is the first sign it is going obsolete.


Having said that, if you want a nice SSH-able router you should load one with firmware running BusyBox, a Linux CLI for tiny clients. But as I said, most routers don't have the hardware to run the Linux kernel, and you pay more for one that does.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript to ssh into router and reboot

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.