LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



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

Rep: Reputation: 15
remote command execute telnet with 1 command


Hello,
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
stefan_nicolau
Member
 
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:
Code:
#!/usr/bin/expect
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
sind
Member
 
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 root@remote.host.com /sbin/reboot

or

$ ssh user@remote.host.com sudo /sbin/reboot

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

alias remote_reboot='ssh root@remote.host.com /sbin/reboot'

alias remote_reboot='ssh user@remote.host.com sudo /sbin/reboot'

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

~sind
 
  


Reply


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


All times are GMT -5. The time now is 10:13 AM.

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