I need to monitor various directories contained in one base directory, 
and notify certain users by email when a file has been added or changed 
in their monitored directory.  I wrote a script using inotifywait, and 
when an event is triggered it fires of an email to the user with the 
location & the new file name.

The script is working, but can generate many emails for one event 
(saving a large file for example).

I have tried many of the different --event types available in 
inotifywait to see if I could get it down to one notification.  No luck 
yet.  Here is the basic outline of the script.  Any thoughts on how I 
might be able to get this to only send one email per file would be 
greatly appreciated.

#!/bin/bash
#
# usage: script DIR email-to-addr

DIR=$1
EMAILTO=$2

inotifywait --recursive --monitor --quiet --exclude '.*\.tmp' \
--event close_write --format '%f' \
/var/www/htdocs/contracts/contracts/$DIR | while read FILE ;
do
{
         echo "To: $EMAILTO"
         echo "From: MONITOR ROBOT <DO-NOT-REPLY at somewhere.com>"
         echo "Subject: Alert - $DIR"
         echo " "
         echo "A new file has been detected in $DIR"
         echo ""
         echo "The New File is named:"
         echo " "
         echo $FILE
} 2>&1 | /usr/bin/sendmail -t
done

Thanks!

Mr. B-o-B