I'm not sure either. But it seems the pipe to while isn't a pipe from 
one executable command output to another executable command input.





Mike Miller wrote:
> Isn't the question here why it would send multiple messages when the
> event is close_write?
>
> I'm not clear on how "while read FILE" works, but that is the part that
> makes me suspicious.
>
> Mike
>
>
> On Wed, 21 Aug 2013, Jake Vath wrote:
>
>> Do you want to stick with Bash for the solution?
>> I've done something similar using Perl, so I bet I could modify it to do
>> something like this.
>> The Perl script uses *Inotify2*, so it's fairly portable.
>>
>> 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.
>> You could only send an email with all the previous information and the
>> body
>> of the emails concatenated together.
>> That way you could build the emails based on some events and then send
>> one
>> email on a specific event.
>> Think of it as a sentinel-controlled event loop.
>>
>> -> Jake
>>
>>
>> On Tue, Aug 20, 2013 at 11:57 PM, B-o-B De Mars
>> <mr.chew.baka at gmail.com>wrote:
>>
>>> 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
>>> ______________________________**_________________
>>> TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
>>> tclug-list at mn-linux.org
>>> http://mailman.mn-linux.org/**mailman/listinfo/tclug-list<http://mailman.mn-linux.org/mailman/listinfo/tclug-list>
>>>
>>>
>>
> _______________________________________________
> TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
> tclug-list at mn-linux.org
> http://mailman.mn-linux.org/mailman/listinfo/tclug-list
>