• Shell script issue; rsync

    From Khelair@DIGDIST/BATTLEST/FREEWAY to All on Saturday, June 13, 2015 00:06:00
    I'm working with the following shell script for automating a task that I need to accomplish for one of my clients... Unfortunately the version that I've written is having some really weird bugs creeping up when it's executed as a shell script. It's proving pretty problematic to debug, as when I throw the script into debugging mode and cut 'n paste the actual command that it's trying to execute into the shell, it works just fine. When it's trying to execute via the script I get the following error:

    -=-=-=-=-
    ./sync_static_to_dev.sh
    Rsyncing /server/assets with options: -vHrltD -e \'ssh -p 22\' dgetsman@10.183.1.251:/server/assets /server/assets
    Unexpected remote arg: dgetsman@10.183.1.251:/server/assets
    rsync error: syntax or usage error (code 1) at main.c(1201) [sender=3.0.6]
    Done
    -=-=-=-=-

    I thought at first that perhaps there was an issue with the way that I had used the quoting within the shell. I've had other weird, esoteric kinds of errors due to quoting incorrectly via shell script previously. So I went back through the script that follows and ended up escaping all occurrances of the single-tick (') quoting, but still ended up getting the same error.
    So anyway, if there are any shell script wizards in the house, any you've got any ideas on why this is failing as a script, but working when I cut 'n paste the debugging output of the command straight into the shell, I'd greatly appreciate any feedback you might be able to offer.
    Script follows:

    -=-=-=-=-
    #!/bin/sh

    # script's functionality is to rsync static assets from whatever directory
    # (specified in constants) from production to whatever directory specified on
    # command line with an optional default (later, meh, nunathismattahs)

    WHICH='/usr/bin/which'

    STATIC_ASSETS='/server/assets'
    SOURCE='10.183.1.251' #use the quick link; this'll break quick

    DEBUGGING=0
    VERBOSE=1

    WHOAMI=`$WHICH whoami`
    RSYNC=`$WHICH rsync`

    if [ -n "$1" ] ; then
    USER=$1
    else
    USER=`$WHOAMI`
    fi

    if [ $VERBOSE -gt 0 ] ; then
    RSYNC_OPTS="-vHrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
    $STATIC_ASSETS"
    else
    RSYNC_OPTS="-HrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
    $STATIC_ASSETS"
    fi

    if [ $DEBUGGING -eq 0 ] ; then
    if [ $VERBOSE -gt 0 ] ; then
    #RSYNC_OPTS="-vHrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
    # $STATIC_ASSETS"

    echo Rsyncing $STATIC_ASSETS with options: $RSYNC_OPTS
    $RSYNC $RSYNC_OPTS
    echo Done
    else
    #RSYNC_OPTS="-HrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
    # $STATIC_ASSETS"

    $RSYNC $RSYNC_OPTS
    fi
    else
    echo $RSYNC $RSYNC_OPTS
    fi

    -=-=-=-=-

    Anything you might be able to offer is greatly appreciated! TIA

    -D/K

    ---
    Borg Burgers: We do it our way; your way is irrelevant.
    þ Synchronet þ Tinfoil Tetrahedron BBS telnet://tinfoil.synchro.net