Hi,
On 2015-06-13 00:06:06, Khelair wrote to All:
about: "Shell script issue; rsync error wtf":
Kh> I'm working with the following shell script for automating a task
Kh> that I
Kh> need to accomplish for one of my clients... Unfortunately the version
that
Kh> I've written is having some really weird bugs creeping up when it's
Kh> executed as a shell script. It's proving pretty problematic to debug, as
Kh> when I throw the script into debugging mode and cut 'n paste the actual
Kh> command that it's trying to execute into the shell, it works just fine.
Kh> When it's trying to execute via the script I get the following error:
Kh> -=-=-=-=-
Kh> ./sync_static_to_dev.sh
Kh> Rsyncing /server/assets with options: -vHrltD -e \'ssh -p 22\'
Kh> dgetsman@10.183.1.251:/server/assets /server/assets
Kh> Unexpected remote arg: dgetsman@10.183.1.251:/server/assets
Kh> rsync error: syntax or usage error (code 1) at main.c(1201) [sender=3.0.6]
Kh> Done
Kh> -=-=-=-=-
Kh> I thought at first that perhaps there was an issue with the way that I
Kh> had used the quoting within the shell. I've had other weird, esoteric
Kh> kinds of errors due to quoting incorrectly via shell script previously.
So
Kh> I went back through the script that follows and ended up escaping all
Kh> occurrances of the single-tick (') quoting, but still ended up getting the
Kh> same error. So anyway, if there are any shell script wizards in the house,
Kh> any you've got any ideas on why this is failing as a script, but working
Kh> when I cut 'n paste the debugging output of the command straight into the
Kh> shell, I'd greatly appreciate any feedback you might be able to
Kh> offer. Script follows:
Kh> -=-=-=-=-
Kh> #!/bin/sh
Kh> # script's functionality is to rsync static assets from whatever directory
Kh> # (specified in constants) from production to whatever directory specified
Kh> on # command line with an optional default (later, meh, nunathismattahs)
Kh> WHICH='/usr/bin/which'
Kh> STATIC_ASSETS='/server/assets'
Kh> SOURCE='10.183.1.251' #use the quick link; this'll break quick
Kh> DEBUGGING=0
Kh> VERBOSE=1
Kh> WHOAMI=`$WHICH whoami`
Kh> RSYNC=`$WHICH rsync`
Kh> if [ -n "$1" ] ; then
Kh> USER=$1
Kh> else
Kh> USER=`$WHOAMI`
Kh> fi
Kh> if [ $VERBOSE -gt 0 ] ; then
Kh> RSYNC_OPTS="-vHrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
Kh> $STATIC_ASSETS"
Kh> else
Kh> RSYNC_OPTS="-HrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
Kh> $STATIC_ASSETS"
Kh> fi
Kh> if [ $DEBUGGING -eq 0 ] ; then
Kh> if [ $VERBOSE -gt 0 ] ; then
Kh> #RSYNC_OPTS="-vHrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
Kh> # $STATIC_ASSETS"
Kh> echo Rsyncing $STATIC_ASSETS with options: $RSYNC_OPTS
Kh> $RSYNC $RSYNC_OPTS
Kh> echo Done
Kh> else
Kh> #RSYNC_OPTS="-HrltD -e 'ssh -p 22' $USER@$SOURCE:$STATIC_ASSETS \
Kh> # $STATIC_ASSETS"
Kh> $RSYNC $RSYNC_OPTS
Kh> fi
Kh> else
Kh> echo $RSYNC $RSYNC_OPTS
Kh> fi
Kh> -=-=-=-=-
Kh> Anything you might be able to offer is greatly appreciated! TIA
What shell is /bin/sh on your system? Have you tried explicitly setting
#!/bin/bash for instance?
As port 22 is the default ssh port, you don't have to specify it. You can just
do -e ssh without the hassel of the quotes, for testing.
I do however always use -e 'ssh -o BatchMode=yes' ... YMMV ...
Bye, Wilfred.
--- FMail-W32-1.69.6.114-B20150605
* Origin: Native IPv6 connectable node (2:280/464)
|