Refer: http://malcontentcomics.com/systemsboy/2006/07/send-remote-commands-via-ssh.html
The basic form looks something like this:
ssh systemsboy@rhost.systemsboy.edu 'ls -l'
where "systemsboy" is actually your username on the remote host, and "rhost.systemsboy.edu" is your remote system. The command you're sending is contained in single quotes.
Here is an example sending multiple commands:
ssh systemsboy@rhost.systemsboy.edu 'ls -l; ps -aux; whoami'
wherein each command is separated by a semicolon.
Finally, here is an example sending a command that requires user interaction:
ssh -t systemsboy@rhost.systemsboy.edu 'top'
Note the -t flag. That tells ssh that you'll be interacting with remote shell. Without the -t flag top will return results after which sshwill log you out of the remote host immediately. With the -t flag, ssh keeps you logged in until you exit the interactive command. The -t flag can be used with most interactive commands, including text editors like pico and vi.
Sending remote commands via ssh is incredibly handy when writing shell scripts as it allows you to run your scripts locally even if those scripts are meant to effect changes on a remote machine. I just wrote a script, for instance, that sets up vacation mail forwarding for staff members. Without these remote commands I would have had to have staff members log directly onto the mail server and run the scripts from the command line, which I don't think they'd be too happy about. With ssh remote commands, I can give them the scripts and they can run them right from their Desktops. Believe me, they much prefer this.
