Or: How do I prevent a sudo'ed rsync from infinite firing in a while-loop? Because that's both what (feels like) is happening and I don't get it.
I am trying to set up a watch for syncing modified files, and it works fine. However, once I introduce the required sudo
to the rsync
command, a single inotify
event causes the rsync
command to fire indefinitely.
#!/usr/bin/env bash
inotifywait -m -r --format '%w%f' -e modify -e move -e create -e delete /var/test | while read line; do
sudo rsync -ah --del --progress --stats --update "$line" "/home/test/"
done
When you edit a file, rsync
goes in rapid fire mode. But lose the sudo
(and use folders to which you have permissions, of course) and the script works as expected.
- Why is this?
- How do I make this work correctly with the
sudo
command?