Run or Execute Multiple Command on SSH

On Jan 6, 2010 0 comments

Sometime you need to run a command or two command or many command on one ssh connection and then exit immediately. To run one command you just need to add the command behind the ssh command, like this :

$ ssh user@remote_computer command

example :
$ ssh john@ ls -l

that command will execute "ls -l" on remote computer ( and display the result on your computer.

But, you may have a question how to run multiple command on ssh. To do that you need to add double quotes at the beginning and the end of your command. Separate every your command with semicolon. Like this :

$ ssh user@remote_computer "command1; command2; command3;"

example :

$ ssh john@ "ls; ls /etc;"

With that command you can execute many command with one ssh connection.


Post a Comment