Article pages now have a discussion option at the bottom (moderated/captcha, but no registration needed)

Run some bash commands with SSH remotely using local variables

Keywords: ssh,variables
Contributor: cweiss

In this example, we want to make sure a certain file exists on the remote server:

file=/tmp/file.log
ssh ${options} ${login} "if [ ! -e '$file' ] ; then touch '$file' ; fi"

Notice the command is surrounded by double quotes, and the $file variable is surrounded by single quotes. That has the effect to be wordsplit-proof in the local shell (due to the double-quotes) and in the remote shell (due to the single-quotes).

Discussion

Enter your comment
 
snipplets/ssh_local_var.txt · Last modified: 2009/02/24 07:18 (external edit)
GNU Free Documentation License 1.2
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0