-   Linux - Networking (
-   -   remote command execute telnet with 1 command (

MPowers 06-30-2005 05:51 AM

remote command execute telnet with 1 command
How I can make a script that connects to a remote computer via telnet and executes a single command (reboot).
The reason that I want to do that is because I want to make a simple script that pings some host and if it is down the linux box will connect via telnet to gateway and reboots it.

stefan_nicolau 06-30-2005 06:04 AM

Create a script with expect that will be invoked from a shell script if ping fails:

spawn telnet mybox
expect {*login:}
send "XXXXXXXX\r"
expect {*password:}
send "XXXXXXXX\r"
expect {*me@mybox# }
send "sudo /sbin/reboot\r"

This code might be slightly wrong. Look at the expect documentation.

WARNING! The username/password combination can be viewed by anyone who reads the script! I use sudo because reboot requires root access, and don't even think about putting the root in a script.

sind 06-30-2005 06:31 AM

If security is an issue, use ssh with a public key setup. Then you could do a remote reboot by running:

$ ssh /sbin/reboot


$ ssh sudo /sbin/reboot

Or even add one of these to your .bashrc file to make it really easy:

alias remote_reboot='ssh /sbin/reboot'

alias remote_reboot='ssh sudo /sbin/reboot'

There should be heaps of info about setting up sshd properly here, or through Google.


All times are GMT -5. The time now is 08:30 AM.