1

Problematic code:

if  [[ $remote == y ]]; then
  RSYNCOPTIONS="&& $SSHOPTIONS $BKUSER@$BKSVR mv incomplete_back-$date $2 && rm -f current && ln -s $2 current"
else
  RSYNCOPTIONS="mv /backup/incomplete_back-$date /backup/$2 && rm -f /backup/current && ln -s /backup/$2 /backup/current"
fi

rsync -ah \
-e "$SSHOPTIONS" \
--ignore-errors \
--delete \
--delete-excluded \
--exclude-from="$BSPATH"/rsync/exclude \
--link-dest=../current \
"$(dirname ${PWD})" "${RSYNCLOCATION}incomplete_back-${date}" "${RSYNCOPTIONS}"

Error:

Unexpected remote arg: username@server.hostname.com:incomplete_back-2019-08-19T20_00_55
rsync error: syntax or usage error (code 1) at main.c(1214) [sender=3.0.9]

if I remove "${RSYNCOPTIONS}" then it completes without error.

if I echo the results of "${RSYNCOPTIONS}"

ssh -oStrictHostKeyChecking=no -i /root/.ssh/wpo_backups username@server.hostname.com mv incomplete_back-2019-08-19T19_24_51 manual-test && rm -f current && ln -s manual-test current

in this instance remote == y

I can run it manually and it does work. If the entire script is needed, I can provide.

JCats
  • 87
  • 2
  • 13
  • 2
    Storing commands in variables (like `RSYNCOPTIONS`) doesn't work, because variables get substituted partway through the process of parsing a line. See [this Stackoverflow question](https://stackoverflow.com/questions/12136948/why-does-shell-ignore-quotes-in-arguments-passed-to-it-through-variables) and [BashFAQ #50](http://mywiki.wooledge.org/BashFAQ/050). My recommendation: do the post-rsync cleanup as normal, separate commands. Do *not* use `eval` -- that way lies madness and weird bugs. – Gordon Davisson Aug 20 '19 at 18:36
  • Appreciate the info – JCats Aug 20 '19 at 18:39

0 Answers0