Display more information, including the path

This commit is contained in:
David Coppit
2015-06-27 15:41:00 -04:00
parent 99f51ecc05
commit 51bb83d62f

View File

@@ -13,42 +13,42 @@ function ts {
function is_change_event { function is_change_event {
EVENT="$1" EVENT="$1"
FILE="$2" INFO="$2"
# File events # File events
if [ "$EVENT" == "ATTRIB" ] if [ "$EVENT" == "ATTRIB" ]
then then
echo "$(ts) Detected file attribute change: $FILE" echo "$(ts) Detected file attribute change: $INFO"
elif [ "$EVENT" == "CLOSE_WRITE,CLOSE" ] elif [ "$EVENT" == "CLOSE_WRITE,CLOSE" ]
then then
EVENT=CLOSE_WRITE EVENT=CLOSE_WRITE
echo "$(ts) Detected new file: $FILE" echo "$(ts) Detected new file: $INFO"
elif [ "$EVENT" == "MOVED_TO" ] elif [ "$EVENT" == "MOVED_TO" ]
then then
echo "$(ts) Detected file moved into dir: $FILE" echo "$(ts) Detected file moved into dir: $INFO"
elif [ "$EVENT" == "MOVED_FROM" ] elif [ "$EVENT" == "MOVED_FROM" ]
then then
echo "$(ts) Detected file moved out of dir: $FILE" echo "$(ts) Detected file moved out of dir: $INFO"
elif [ "$EVENT" == "DELETE" ] elif [ "$EVENT" == "DELETE" ]
then then
echo "$(ts) Detected deleted file: $FILE" echo "$(ts) Detected deleted file: $INFO"
# Directory events # Directory events
elif [ "$EVENT" == "ATTRIB,ISDIR" ] elif [ "$EVENT" == "ATTRIB,ISDIR" ]
then then
echo "$(ts) Detected dir attribute change: $FILE" echo "$(ts) Detected dir attribute change: $INFO"
elif [ "$EVENT" == "CREATE,ISDIR" ] elif [ "$EVENT" == "CREATE,ISDIR" ]
then then
echo "$(ts) Detected new dir: $FILE" echo "$(ts) Detected new dir: $INFO"
elif [ "$EVENT" == "MOVED_TO,IS_DIR" ] elif [ "$EVENT" == "MOVED_TO,IS_DIR" ]
then then
echo "$(ts) Detected dir moved into dir: $FILE" echo "$(ts) Detected dir moved into dir: $INFO"
elif [ "$EVENT" == "MOVED_FROM,IS_DIR" ] elif [ "$EVENT" == "MOVED_FROM,IS_DIR" ]
then then
echo "$(ts) Detected dir moved out of dir: $FILE" echo "$(ts) Detected dir moved out of dir: $INFO"
elif [ "$EVENT" == "DELETE,ISDIR" ] elif [ "$EVENT" == "DELETE,ISDIR" ]
then then
echo "$(ts) Detected deleted dir: $FILE" echo "$(ts) Detected deleted dir: $INFO"
else else
return 1 return 1
@@ -194,7 +194,7 @@ pipe=$(mktemp -u)
mkfifo $pipe mkfifo $pipe
echo "$(ts) Waiting for changes to $WATCH_DIR..." echo "$(ts) Waiting for changes to $WATCH_DIR..."
inotifywait -r -m -q --format '%e %f' $WATCH_DIR >$pipe & inotifywait -r -m -q --format 'EVENT=%e WATCHED=%w FILE=%f' $WATCH_DIR >$pipe &
last_run_time=0 last_run_time=0
@@ -207,10 +207,10 @@ do
echo "$(ts) [DEBUG] $RECORD" echo "$(ts) [DEBUG] $RECORD"
fi fi
EVENT=$(echo "$RECORD" | cut -d' ' -f 1) EVENT=$(echo "$RECORD" | sed 's/EVENT=\([^ ]*\).*/\1/')
FILE=$(echo "$RECORD" | cut -d' ' -f 2-) INFO=$(echo "$RECORD" | sed 's/EVENT=[^ ]* //')
if ! is_change_event "$EVENT" "$FILE" if ! is_change_event "$EVENT" "$INFO"
then then
continue continue
fi fi