#!/bin/bash -e
# Use with crontab entry like:
-# */5 * * * * $HOME/bin/monitor_dir /path/to/something
+# */5 * * * * $HOME/bin/monitor-dir /path/to/something
if [ -z "$1" ]; then
- echo "Usage $0 dir [monitor_file] [ls]"
- exit 1
+ echo "Usage $0 dir [monitor_file] [ls]"
+ exit 1
fi
mon="${2:-$1/.monitor_dir}"
mon_tmp="${mon}_tmp"
${3:-ls} "$1" > "$mon_tmp"
if [ -r "$mon" ] && ! cmp -s "$mon" "$mon_tmp" && [ -n "$(ls "$1")" ]; then
- comm -13 "$mon" "$mon_tmp"
+ comm -13 "$mon" "$mon_tmp"
fi
mv "$mon_tmp" "$mon"