Last active
March 29, 2021 02:45
-
-
Save dan82840/789c951fc668867f8832d0dd4bd3f05f to your computer and use it in GitHub Desktop.
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/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