Quote exclusion when using SSH

I am trying to create a simple deployment script for my PHP applications. I know that there are several tools for this work (Capistrano, Phing, etc.), but they seem very useful for my simple deployment procedure.

I use sshpass to not enter my password again and again. But after downloading my compressed installer, I need ssh to the server and run some commands. One of them is sed. So the quotation marks break my script. This is something like this:

sshpass -p foo ssh user @ host "
   cd / www / htdocs / foo / bar 
   echo 'Untar and remove installer'
   tar -zxf install.tar.gz

   sed "s / define ('ENVIRONMENT', 'development'); / define ('ENVIRONMENT', 'production');" index.php> tmp && mv tmp index.php
   sed "s / define ('ENVIRONMENT', 'development'); / define ('ENVIRONMENT', 'production'); /" admin / index.php> tmp && mv tmp admin / index.php

"

As you can see, I use double quotes to run my SSH statements, but I also need to use them in sed.

Any suggestions would be greatly appreciated. Thank!

+5
source share
2 answers

Eliminating inner quotation marks is the usual way. Does this work?

sshpass -p foo ssh user@host "
cd /www/htdocs/foo/bar
echo 'Untar and remove installer'
tar -zxf install.tar.gz

sed \"s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');\" index.php > tmp && mv tmp index.php
sed \"s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');/\" admin/index.php > tmp && mv tmp admin/index.php

"
+6
source

-?:

sshpass -p foo ssh user@host <<DATA
   cd /www/htdocs/foo/bar 
   echo 'Untar and remove installer'
   tar -zxf install.tar.gz

   sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');" index.php > tmp && mv tmp index.php
   sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');/" admin/index.php > tmp && mv tmp admin/index.php
DATA
+2

All Articles