I have SSH executing some commands in a script, like so:
#!/bin/bash REMOTEUSER=$1 REMOTEHOST=$2 newVh=$3 ssh "$REMOTEUSER"@"$REMOTEHOST" << EOF cd if [ ! -d "/data/web/someDirectory" ] then echo -e "There is no vhost setup for someDirectory" exit 1 fi if [ ! -d "git" ] then echo -e "Home git directory not found. Creating it now." mkdir git fi if [ ! -d "git/$newVh.git" ] then echo -e "Bare git repository not found for $new. Creating it now." mkdir git/"$newVh".git git init --bare git/"$newVh".git fi EOF
Which works fine and does what I want. I'm trying to check if the
compass ruby gem is installed on the remote machine and if it's not, I want to install it. I added this line to the bottom of the script:
. . . if [ `gem list compass -i` == 'false' ] then echo -e "Compass not installed... Installing it now." gem install compass -V fi EOF
`gem list compass -i`. is getting evaluated on my local machine beforehand (I have compass installed). Even running
gem list compass -i in the script with no quotes to see the output is returning
true which is incorrect. I tried escaping the command with a number of
\s but it didn't work.
I guess two questions:
How is it that other commands in the script (
git init etc...) work correctly on the remote machine but
gem list does not?
How do I escape that command to run it remotely?