DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Aaron has posted 1 posts at DZone. View Full User Profile

Monitor Directory For Changes

05.22.2009
| 6143 views |
  • submit to reddit
        From <a href="http://www.refactory.org/s/monitor_directory_for_changes_time_based/view/latest">http://www.refactory.org/s/monitor_directory_for_changes_time_based/view/latest</a>

Checks if a directory's contents have been changed every 10 seconds

#!/bin/sh
 
check() {
    dir="$1"
    for="$2"
    chsum1=`digest -a md5 $dir | awk '{print $1}'`
    chsum2=$chsum1
 
    while [ $chsum1 -eq $chsum2 ]
    do
        sleep $for
        chsum2=`digest -a md5 $dir | awk '{print $1}'`
    done
 
    echo "$0: $dir changed." >&
}
 
check $*