Ssh Run a Remote Command: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * ssh Client =Overview=")
 
No edit summary
Line 4: Line 4:


=Overview=
=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]

Revision as of 20:41, 14 October 2016

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]