0

I am trying to run rsync from a batch file. The command is

SET CMD="rsync -P -rptz --delete -e 'ssh -i /root/.ssh/CERTIFICATE.pem' SOURCE_ADDRESS  /mnt/c/Users/MYNAME/IdeaProjects/PROJECT/SUBFOLDER/SUBFOLDER/SUBFOLDER/SUBFOLDER/LASTFOLDER"

bash %CMD%

This works fine if I run the command after typing bash, but when I run the command from cmd with the bash precursor it says No such file or directory.

Additionally, when playing around and trying to debug bash ends up hanging... i.e. if I open bash I get no prompt, just a blinking cursor.

Any help is appreciated.

Compo
  • 36,585
  • 5
  • 27
  • 39
gunslingor
  • 1,358
  • 12
  • 34

1 Answers1

2

To run a command with bash you need to use the -c option

bash -c "%CMD%"

Without it the first non-option parameter will be treated as a *.sh shell script, which rsync isn't and will cause an error

If arguments remain after option processing, and neither the -c nor the -s option has been supplied, the first argument is assumed to be the name of a file containing shell commands.

Note that the cmd in Windows is not DOS even though they have a few similar commands. The rest are vastly different

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • Thank you, I found that running it with -c wouldn't give the --info=progress2 information... or maybe it was due to the blinking cursor issue above. Regardless, this does 100% work. Another solution I found, separate the CMD into a shell script and you can run that without the -c. This did, seem, to cause windows/linux permission conflicts and creating the wsl.config file seemed to correct it. – gunslingor May 22 '19 at 19:50
  • the `--info=progress2` works fine on my PC. Probably some issues with your rsync that stops printing the progress in non-interactive mode because it thinks the output may be a file. Try `bash -i` or [`bash --init-file <(echo "rsync -- ..")`](https://unix.stackexchange.com/q/253748/44425) instead. But you don't even need rsync for this. There's the built-in [robocopy](https://ss64.com/nt/robocopy.html) for exactly the same purpose, or you can [install rsync for Windows](https://stackoverflow.com/q/30526848/995714) – phuclv May 23 '19 at 00:07
  • Yes, that does work, I stand corrected. However, no matter what I do after I run my first rsync I have the blicking cursor and not prompt error, so my batch script hangs completely when trying to perform the second rsync. Even if I open a second ubuntu on windows terminal I still get the blinking cursor issue. I've tried this with and without an exit statement in my shell scripts that are called from the batch file, with and without the -c too. I can only restart to fix it... the only way to run both seems to be to enter bash and paste both rsync cmds in, nothing else works. – gunslingor May 23 '19 at 13:52
  • Still having that ubuntu hanging issue, it just stops completely after the first rsync command and I'm forced to restart (one batch file calling 2 one line rsync command shell files, with shebang... my brain is telling me this is an EOL issue, but the sh files use LF and batch uses CRLF). You say robocopy could be used instead? Keep in mind the source, and or destination, is usually a remote aws linux server. Is it still true and if so, how would I convert the current command (that would make life easier)? – gunslingor May 24 '19 at 12:10
  • it's a different issue so please ask another question. It may be more suitable on [ubuntu.se]. And if you can create a samba share you can use robocopy. [Robocopy to copy files and folders to and fro between a location on Windows and UNIX](https://superuser.com/q/1201831/241386) – phuclv May 24 '19 at 12:20