Ssh Run a Remote Command

From NovaOrdis Knowledge Base
Revision as of 20:41, 14 October 2016 by Ovidiu (talk | contribs)
Jump to navigation Jump to search

Internal

Overview

!!!Multiple Remote Commands in the Same SSH Invocation

{{{

   ssh ovidiu@192.168.1.1 "ls ~; echo 'blah'; ls /tmp"

}}}

!Important

If storing the ssh command in a local variable and executing the local variable, the double quotes around the multiple commands are not necessary. This works

{{{ ssh_command="ssh ovidiu@192.168.1.1 ls ~; echo 'blah'; ls /tmp" ${ssh_command} }}}

!Important 2

To avoid local shell substitution inside the remote command, escape $:

{{{

    ssh ovidiu@192.168.1.1 "\$(hostname)"

}}}

will return the remote hostname.

!!!Multiple Commands with sudo Over ssh

|[sudo#MultipleCommandsWithSudoOverSsh]