<div dir="ltr"><div><div>Do you want to stick with Bash for the solution?<br></div>I've done something similar using Perl, so I bet I could modify it to do something like this.<br></div><div>The Perl script uses <i>Inotify2</i>, so it's fairly portable.<br>
</div><div><br></div><div>If you want to stick with Bash, maybe you could assemble your email into a few different strings, such as  to, from, subject, and body.<br></div><div>You could only send an email with all the previous information and the body of the emails concatenated together.<br>
</div><div>That way you could build the emails based on some events and then send one email on a specific event.<br></div><div>Think of it as a sentinel-controlled event loop.<br></div><div><br></div>-> Jake<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Aug 20, 2013 at 11:57 PM, B-o-B De Mars <span dir="ltr"><<a href="mailto:mr.chew.baka@gmail.com" target="_blank">mr.chew.baka@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>

<br>
The script is working, but can generate many emails for one event (saving a large file for example).<br>
<br>
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.<br>

<br>
#!/bin/bash<br>
#<br>
# usage: script DIR email-to-addr<br>
<br>
DIR=$1<br>
EMAILTO=$2<br>
<br>
inotifywait --recursive --monitor --quiet --exclude '.*\.tmp' \<br>
--event close_write --format '%f' \<br>
/var/www/htdocs/contracts/<u></u>contracts/$DIR | while read FILE ;<br>
do<br>
{<br>
        echo "To: $EMAILTO"<br>
        echo "From: MONITOR ROBOT <<a href="mailto:DO-NOT-REPLY@somewhere.com" target="_blank">DO-NOT-REPLY@somewhere.com</a>>"<br>
        echo "Subject: Alert - $DIR"<br>
        echo " "<br>
        echo "A new file has been detected in $DIR"<br>
        echo ""<br>
        echo "The New File is named:"<br>
        echo " "<br>
        echo $FILE<br>
} 2>&1 | /usr/bin/sendmail -t<br>
done<br>
<br>
Thanks!<br>
<br>
Mr. B-o-B<br>
______________________________<u></u>_________________<br>
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota<br>
<a href="mailto:tclug-list@mn-linux.org" target="_blank">tclug-list@mn-linux.org</a><br>
<a href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list" target="_blank">http://mailman.mn-linux.org/<u></u>mailman/listinfo/tclug-list</a><br>
</blockquote></div><br></div>