![]() |
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. |
Create a script with expect that will be invoked from a shell script if ping fails:
Code:
#!/usr/bin/expect 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. |
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 |
All times are GMT -5. The time now is 04:03 PM. |