Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 06-30-2005, 06:51 AM   #1
LQ Newbie
Registered: Jun 2005
Posts: 25

Rep: Reputation: 15
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.
Old 06-30-2005, 07:04 AM   #2
Registered: Jun 2005
Location: Canada
Distribution: Debian Etch/Sid, Ubuntu
Posts: 529

Rep: Reputation: 32
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.
Old 06-30-2005, 07:31 AM   #3
Registered: Jun 2005
Posts: 75

Rep: Reputation: 15
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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
execute system command from c alaios Programming 2 07-19-2005 08:45 AM
execute system command in c alaios Programming 3 07-13-2005 06:26 AM
command execute without ./ kaon Slackware 11 09-15-2004 06:14 PM
Execute Command lawrencegoodman Linux - Newbie 2 10-23-2003 09:36 AM
execute command as different user kilobravo Linux - General 2 06-02-2003 11:03 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:22 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration