From 527be7ae1668d9ebc0c3450233299c6c618830a7 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Thu, 11 Oct 2012 21:46:47 +1100 Subject: [PATCH] monitor-dir: track changes in a directory --- monitor-dir | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 monitor-dir diff --git a/monitor-dir b/monitor-dir new file mode 100755 index 0000000..6f1c940 --- /dev/null +++ b/monitor-dir @@ -0,0 +1,18 @@ +#!/bin/bash -e + +# Use with crontab entry like: +# */5 * * * * $HOME/bin/monitor_dir /path/to/something + +if [ -z "$1" ]; then + echo "Usage $0 dir [monitor_file]" + exit 1 +fi +mon="$1/${2:-.monitor_dir}" +mon_tmp="${mon}_tmp" + +ls -R "$1" > "$mon_tmp" +if [ -r "$mon" ] && ! cmp -s "$mon" "$mon_tmp" && [ -n "$(ls "$1")" ]; then + cat "$mon_tmp" +fi +mv "$mon_tmp" "$mon" + -- 2.39.2