Skip to content

Instantly share code, notes, and snippets.

@dan82840
Last active March 29, 2021 02:45
Show Gist options
  • Save dan82840/789c951fc668867f8832d0dd4bd3f05f to your computer and use it in GitHub Desktop.
Save dan82840/789c951fc668867f8832d0dd4bd3f05f to your computer and use it in GitHub Desktop.
#!/bin/sh /etc/rc.common
#
# inotify-dir.sh start [dir/to/monitor]
# stop
#
_inotify() {
local dir="$1"
local d
inotifywait -mrq --exclude '(.bki/*|.uci/*|.runtime/*)' --format '%w%f %e' -e modify,delete,create,move,close ${dir} |
while read file command; do
case $command in
MODIFY|CREATE|MOVED_TO)
d=$(date +"%m-%d %H:%M:%S")
echo "[$d] Create $file !!! ($command)"
;;
DELETE|MOVED_FROM)
d=$(date +"%m-%d %H:%M:%S")
echo "[$d] Delte $file !!! ($command)"
;;
CLOSE_WRITE,CLOSE)
d=$(date +"%m-%d %H:%M:%S")
echo "[$d] Close $file !!! ($command)"
;;
esac
done
}
start() {
local dir=${1:-/tmp}
_inotify ${dir} &
}
stop() {
pkill inotifywait
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment