Skip to content

Instantly share code, notes, and snippets.

@sevenissimo
Created June 30, 2022 19:19
Show Gist options
  • Select an option

  • Save sevenissimo/a4a13da82c9561430fb70ff61722f73d to your computer and use it in GitHub Desktop.

Select an option

Save sevenissimo/a4a13da82c9561430fb70ff61722f73d to your computer and use it in GitHub Desktop.
Linux Inotify events handling in Bash
#!/bin/bash
#set -x
dir="$(mktemp -d)"
mkfifo "${fifo:=$dir/FIFO}"
inotifywait -m -e create $dir 1>$fifo 2>/dev/null & jobs %%
for i in {1..10}; do
( sleep 2; touch "$dir/$i" ) &
read event <$fifo
printf '[%(%c)T] %s\n' -1 "$event"
done
wait
echo "All finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment