2023-07-05 11:33:45 +02:00
|
|
|
# Run some bash commands with SSH remotely using local variables
|
|
|
|
|
2024-04-01 06:10:32 +02:00
|
|
|
---- dataentry snipplet ---- snipplet_tags: ssh, variables
|
2023-07-05 11:33:45 +02:00
|
|
|
LastUpdate_dt: 2010-07-31 Contributors: cweiss type: snipplet
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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).
|