3 # Watch current directory (recursively) for file changes, and execute
4 # a command when a file or directory is created, modified or deleted.
6 # Written by: Senko Rasic <senko.rasic@dobarkod.hr>
8 # Requires Linux, bash and inotifywait (from inotify-tools package).
10 # To avoid executing the command multiple times when a sequence of
11 # events happen, the script waits one second after the change - if
12 # more changes happen, the timeout is extended by a second again.
15 # chmod a+rx onchange.sh
16 # sudo cp onchange.sh /usr/local/bin
18 # Example use - rsync local changes to the remote server:
20 # onchange.sh rsync -avt . host:/remote/dir
22 # Released to Public Domain. Use it as you like.
25 EVENTS="CREATE,CLOSE_WRITE,DELETE,MODIFY,MOVED_FROM,MOVED_TO"
28 echo "Usage: $0 cmd ..."
32 inotifywait -e "$EVENTS" -m -r --format '%:e %f' . | (
37 if test -z "$LINE"; then
38 if test ! -z "$WAITING"; then