Last active
December 4, 2020 15:02
-
-
Save nico/5bd81b9f887abd48e29f70cdb0978b0c to your computer and use it in GitHub Desktop.
inotifywait -m with event coalescing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
inotifywait -m -e create -r $1 | while read dir action file; do | |
# Coalese additional queued up events, if any | |
# If events keep arriving faster than we can read them off stdin here, | |
# we'll never run the script! If you're worried about that, set | |
# SECONDS to 0 before this loop and make the conditional also check that | |
# $SECONDS is smaller than some timeout to make sure that the script runs | |
# every now and then. The stdin pipe buffer size means there won't be an | |
# unbounded buildup on stdin -- instead inotifywait will block writing | |
# output on its side. Not sure that's much better :) | |
while read -t 0; do | |
read line | |
echo skipping $line | |
done | |
echo got $dir $action $file | |
# simulate a command that takes some time: | |
sleep 3 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment