]> code.delx.au - mediapc-tools/commitdiff
monitor_dir: more options & only display diff
authorJames Bunton <jamesbunton@delx.net.au>
Mon, 15 Oct 2012 08:29:59 +0000 (19:29 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Mon, 15 Oct 2012 08:29:59 +0000 (19:29 +1100)
monitor-dir

index ba220b1e8c9efdd0c286b8fa556bfe0af9cff373..5277f56f443acd4f337f0f87e50211998661b79e 100755 (executable)
@@ -4,15 +4,15 @@
 #   */5 *   *   *   *     $HOME/bin/monitor_dir /path/to/something
 
 if [ -z "$1" ]; then
-       echo "Usage $0 dir [monitor_file]"
+       echo "Usage $0 dir [monitor_file] [ls-options]"
        exit 1
 fi
-mon="$1/${2:-.monitor_dir}"
+mon="${2:-$1/.monitor_dir}"
 mon_tmp="${mon}_tmp"
 
-ls -tlR "$1" > "$mon_tmp"
+ls "${3:--tlR}" "$1" > "$mon_tmp"
 if [ -r "$mon" ] && ! cmp -s "$mon" "$mon_tmp" && [ -n "$(ls "$1")" ]; then
-       cat "$mon_tmp"
+       diff "$mon" "$mon_tmp" | grep '^> ' | sed 's/^> //'
 fi
 mv "$mon_tmp" "$mon"