Tim S.
Tim S.

Reputation: 385

Cygwin command works from command line but not from script

When I run the command:

rsync -avzhu --progress --exclude node_modules -e 'ssh -p 2022' /cygdrive/d/stuff_to_backup [email protected]:/home2/user/backup

It works fine from the command line, but when the exact same command from a shell script then it throws this error:

The source and destination cannot both be remote.
rsync error: syntax or usage error (code 1) at main.c(1261) [Receiver=3.1.1]

Any ideas why this might be happening?

Upvotes: 1

Views: 735

Answers (1)

Tim S.
Tim S.

Reputation: 385

Spent a good chunk of the evening trying to figure this out, so hopefully this helps someone else someday.

The other error that I would get a lot of as I fiddled with this issue is:

Unexpected remote arg: C:/Program Files (x86)/Git/cygdrive/c/Users

And since I noticed it only threw the errors from a shell script and not the command line I was able to determine that it was working fine from windows without cygwin (cmd.exe), it was just running from bash where it was having issues.

Most of the issues I had seemed to be quote related and something weird happening with the path that I had for the source. I tried to use a path like "/cygdrive/d/backup_dir" but that was somehow being turned into or interpreted as "C:/Program Files (x86)/Git/cygdrive/d/backup_dir" which caused errors. This wasn't an issue after I switched to relative paths without "cygdrive". I use cmder so maybe that caused it?

Anyway, the final fix was to omit the "cygdrive" part and use a relative path. Also, don't get over zealous with quotes '"'.

Upvotes: 2

Related Questions