SSH Executing Remote Commands

One nifty feature of ssh that I sometimes forget to take advantage of is that you can use it to execute commands on a remote server and then promptly log you back out. Say for example that I would like to log onto a remote machine just to check the tail output of some log file. Instead of running ssh to log in, executing the command manually, and the logging back out; the whole operation can be performed as:

ssh myname@myhost ‘tail /path/to/logfile’

Inside of the single quotes is the command to execute. For programs that are user-interactive, such as top, you can pass the -t flag to ssh. I didn’t know this before, I found out today while reading systemsboy’s blog :-)

ssh -t myname@myhost ‘top’

With this newfound ssh knowledge, I decided to put it to work by building some server control scripts. I now have scripts to shutdown, and restart my server which I can execute from my laptop :-)

About Bryan St. Amour

Why yes! I do own this place!
This entry was posted in Code, Etc, Stuff and Junk and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>