0

I am using fswatch and rsync to automatically sync directories between Mac and ubuntu servers. The shell is like

/Users/david/Documents/code/shell/fswatch_rsync.sh:

#!/bin/bash
sudo fswatch -o /Users/david/Documents/code/python/ | xargs -n1 /Users/david/Documents/code/shell/rsync_shell.sh

/Users/david/Documents/code/shell/rsync_shell.sh:

sudo rsync -vzrp --delete /Users/david/Documents/code/python/ --password-file=/etc/rsyncd.pass -e "ssh -i /Users/david/.ssh/id_rsa -p 22" 192.168.0.109::python

However, when I run bash /Users/david/Documents/code/shell/fswatch_rsync.sh in terminal and change the files in /Users/david/Documents/code/python/, it responses:

xargs: ‎⁨/Users/david/Documents/code/shell/rsync_shell.sh: No such file or directory

in the terminal.

david
  • 842
  • 2
  • 8
  • 25
  • what does `ls -l /Users/david/Documents/code/shell/rsync_shell.sh` display? – jhnc Feb 26 '19 at 16:37
  • Maybe it needs a `#!` at the top of the second script? – ams Feb 27 '19 at 15:09
  • @jhnc, it returns -rw-r--r-- 1 david staff 122 2 26 16:32 /Users/david/Documents/code/shell/rsync_shell.sh – david Feb 28 '19 at 09:10
  • try adding a semi-colon at the end of the line: `.../rsync_shell.sh;` – jhnc Feb 28 '19 at 09:18
  • When I change /Users/david/Documents/code/shell/fswatch_rsync.sh like ```#!/bin/bash sudo fswatch -o /Users/david/Documents/code/python/ | xargs -n1 sudo bash ./rsync_shell.sh ``` , run the shell after changing the working directory by ```cd /Users/david/Documents/code/shell/``` in terminal and finally it works. Therefore I think it should be some problems with the running path of the shell. – david Feb 28 '19 at 09:23
  • Glad you've found an answer. I suspect the underlying cause of the problem is that `rsync_shell.sh` is not executable. `chmod +x` should fix that. Another potential problem (possibly not in this case) is that if the line ends with `\r` instead of `\n`, bash can misinterpret the `\r` as part of the command (hence my suggestion to append a semi-colon). – jhnc Feb 28 '19 at 11:51

0 Answers0