Skip to content

Instantly share code, notes, and snippets.

@stigok
Created July 30, 2017 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stigok/3af2ecfba3a6d419646ac212d4871234 to your computer and use it in GitHub Desktop.
Save stigok/3af2ecfba3a6d419646ac212d4871234 to your computer and use it in GitHub Desktop.
File system watcher that executes a command when MOVED_TO event occurs, i.e. when rsync file transfer is complete
#!/bin/bash
# Do something after rsync completes
#
# Usage: after-rsync <srcdir> <command> [...args]
set -x
srcdir=$1
shift
inotifywait -m -r -e MOVED_TO --format='%f %w' "$srcdir" |
grep -ve '^\.' --line-buffered | # ignore temporary rsync files
while read filename directory
do
${@}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment