<div dir="ltr"><div>Ha, I just noticed that I used the wrong email in my script.<br>So, if anyone is wondering with the email address changed... it was user error.<br>Sorry about that.<br><br></div>-> Jake<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Aug 23, 2013 at 6:57 AM, Jake Vath <span dir="ltr"><<a href="mailto:jake.vath@gmail.com" target="_blank">jake.vath@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div><div><div><div><div><div><div><div>I modified the script a bit.<br></div>I added <i>set -e</i> to the script and removed the pipe to <i>sendmail<br></i></div>All of the output is being directed to <i>stdout</i>.<div class="im">
<br>
<br>#!/bin/bash<br>#<br># usage: script DIR email-to-addr<br></div>set -e<br><br>DIR=$1<br>EMAILTO=$2<br><br>/usr/bin/inotifywait --recursive \<div class="im"><br>                           --monitor \<br>                           --quiet \<br>

                           --exclude '.*\.tmp' \<br>                            --event close_write \<br>                           --format '%f' \<br></div>                           /home/jake/tmp/$DIR | while read FILE;<div class="im">
<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<br></div>done<br><br></div>I executed the script like this:<br></div>    jake@server:~$ ./mailme.sh dirToWatch <a href="mailto:jake.vath@gmail.com" target="_blank">jake.vath@gmail.com</a><br></div><div><br>
</div>Only get one "email" per file that I created.<br>
</div>Granted the email is not sent through <i>sendmail</i>.<br><br></div>After running this:<br></div><div>   jake@server:~$ touch tmp ./dirToWatch/tmp<br></div><div><div style="margin-left:40px"><br></div>I get a "email" like this in my shell:<br>

</div><i>To: <a href="mailto:jvath@erdc.k12.mn.us" target="_blank">jvath@erdc.k12.mn.us</a></i><br><i>From: MONITOR ROBOT <<a href="mailto:DO-NOT-REPLY@somewhere.com" target="_blank">DO-NOT-REPLY@somewhere.com</a>></i><br>
<i>Subject: Alert - dirToWatch</i><br>
<br><i>A new file has been detected in dirToWatch</i><div class="im"><br><br><i>The New File is named:</i><br><br></div><i>tmp</i><br><br></div><div>Do you think that it would be something with your mail server or <i>sendmail</i>?<br>
</div><div>
<br></div><div>Mike, when I created some test files $FILE always changed.<br><br></div><div>Actually, I'm a little confused by the <i>2>&1 | /usr/bin/sendmail -t</i> at the end of your do-while loop.<br></div>
<div>
I know that <i>2>&1</i> is going to redirect <i>stderr</i> to <i>stdout</i>, but that redirection only takes place IFF there <i>is</i> and error, correct?<br></div><div>If that is correct and the normal output is going through the pipe to <i>sendmail</i> just like it looks like.<br>

<br></div><div>On a slightly related note, I read the man page for <i>sendmail</i> and came across this:<br><blockquote><i>Notes</i><br><br><i>sendmail often gets blamed for many problems that are actually the result of other problems, such as overly permissive modes on directories. For this reason, sendmail checks the modes on system directories and files to determine if they can be trusted. Although these checks can be turned off and your system security reduced by setting the DontBlameSendmail option, the permission problems should be fixed. For more information, see:</i><br>

<br><i><a href="http://www.sendmail.org/tips/DontBlameSendmail.html" target="_blank">http://www.sendmail.org/tips/DontBlameSendmail.html</a></i><br></blockquote></div><div>I thought it was comical, as I'm sure they do get a lot bug reports that are not <i>really</i> bugs in <i>sendmail</i>.<span class="HOEnZb"><font color="#888888"><br>

</font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div>-> Jake<br></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 23, 2013 at 3:25 AM, Mike Miller <span dir="ltr"><<a href="mailto:mbmiller+l@gmail.com" target="_blank">mbmiller+l@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Are the multiple email messages identical, or does $FILE change?<span><font color="#888888"><br>
<br>
Mike</font></span><div><div><br>
<br>
<br>
On Thu, 22 Aug 2013, Rick Engebretson wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br>
<br>
Mike Miller wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Isn't the question here why it would send multiple messages when the<br>
event is close_write?<br>
<br>
I'm not clear on how "while read FILE" works, but that is the part that<br>
makes me suspicious.<br>
<br>
Mike<br>
<br>
<br>
On Wed, 21 Aug 2013, Jake Vath wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Do you want to stick with Bash for the solution?<br>
I've done something similar using Perl, so I bet I could modify it to do<br>
something like this.<br>
The Perl script uses *Inotify2*, so it's fairly portable.<br>
<br>
If you want to stick with Bash, maybe you could assemble your email<br>
into a<br>
few different strings, such as to, from, subject, and body.<br>
You could only send an email with all the previous information and the<br>
body<br>
of the emails concatenated together.<br>
That way you could build the emails based on some events and then send<br>
one<br>
email on a specific event.<br>
Think of it as a sentinel-controlled event loop.<br>
<br>
-> Jake<br>
<br>
<br>
On Tue, Aug 20, 2013 at 11:57 PM, B-o-B De Mars<br>
<<a href="mailto:mr.chew.baka@gmail.com" target="_blank">mr.chew.baka@gmail.com</a>>wrote:<br>
<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><<a href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list" target="_blank">ht<u></u>tp://mailman.mn-linux.org/<u></u>mailman/listinfo/tclug-list</a>><br>


<br>
<br>
</blockquote>
<br>
</blockquote>
______________________________<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>
<br>
</blockquote>
______________________________<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>
<br>
</blockquote>
______________________________<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>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>