LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash script to rsync remote dir with options (http://www.linuxquestions.org/questions/linux-general-1/bash-script-to-rsync-remote-dir-with-options-666334/)

uopjohnson 08-29-2008 01:07 PM

bash script to rsync remote dir with options
 
I have a bash script which takes some options and from them it syncs local changes up to the webserver using rsync. My problem is that I cannot get it to just run the rsync command I can only get it to echo the command out and then I copy paste to run it. Hopefully the example will make it all clear.
Code:

if [ -z $2 ]; then
  echo "Direcotry Required"
  exit 1
fi
DIR="~/sites/$2/"
if [ ! -d $DIR ]; then
  echo "$DIR doesn't exist"
  exit 1
fi
RSYNC_CMD='/usr/bin/rsync'
ARGS='--delete -ua  --exclude ".svn/"'
case "$1" in
  private)
    SSH='-e "ssh"'
    DESTINATION="user@webtest:/var/www/html/user/$2"
    ;;
  shared)
    SSH='-e "ssh -p 8642"'
    DESTINATION="user@webtest:/var/www/html/testing/$2"
    ;;
  *)
    echo "Need to specific shared or private destination"
    exit 1
esac
CMD="${RSYNC_CMD} ${ARGS} ${SSH} ${DIR} ${DESTINATION}"
echo $CMD

I would like the last line to be
Code:

CMD
and that would just run the rcync command, unfortunately that doesn't work. I get the error
Code:

Missing trailing-' in remote-shell command.
Which I assume is happening becuase my CMD string is not being put together well. Or because I have no idea what I'm doing :)
Any help appreciated,

acid_kewpie 08-30-2008 05:51 AM

well the error is, i think, an rsync error, but you're not actually *running* rsync at all there, if you're just echoing out a string which just happens to include the words to stdout. if you do an "eval $CMD" what happens?

uopjohnson 09-01-2008 02:48 PM

I knew it was something small. Thanks. eval did the trick.

Wizard09 04-23-2010 01:16 AM

I realize that this is an old thread but just wanted to say that I have the same issue and eval was the solution for me.


All times are GMT -5. The time now is 08:09 PM.