<div dir="ltr">oh, and as far as my implied question of &quot;what if I want more email?&quot;, now that I have the context of the while being in a subshell, the most straightforward approach seems to be to initiate the while loop with a variable, and split the reporting/logging of the error from the detection of the error. That way, you can make the loop exit on error detection, and then report and log the error outside the while without unusual for loops or weird redirection.<div>

<br></div><div>Q</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 19, 2014 at 5:32 PM, Quentin Hartman <span dir="ltr">&lt;<a href="mailto:qhartman@gmail.com" target="_blank">qhartman@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I hadn&#39;t considered that the while loop opens a subshell, that&#39;s almost certainly it.<div><br></div>

<div>Thanks!</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Q</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, May 19, 2014 at 5:20 PM, Mike Nolte <span dir="ltr">&lt;<a href="mailto:obiwanmikenolte@gmail.com" target="_blank">obiwanmikenolte@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr">QH,<div><br></div><div>I&#39;m a little unclear on the specifics, but a &quot;while&quot; loop opens a subshell, which could be why it&#39;s being buffered.  You could use a for loop, use redirection instead of tee (&gt;&gt;), or something like that.</div>




<div><br></div><div>~Monkeypenny</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Mon, May 19, 2014 at 5:09 PM, Quentin Hartman <span dir="ltr">&lt;<a href="mailto:qhartman@gmail.com" target="_blank">qhartman@gmail.com</a>&gt;</span> wrote:<br>




</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">I have a script that looks roughly like:<div><br></div><div>now=`date +%F`<br>
</div><div>logfile = log-$now.log</div>

<div><div>while [ 1 -eq 1 ]</div><div>do</div><div> things</div><div>  if [ $? -ne 0 ]<br>

</div><div>  then  </div><div>   echo &quot;Oh noes!&quot; | tee -a $logfile</div><div>  fi</div><div>done</div></div><div><br></div><div>And it&#39;s run via cron, and everyday at midnight cron kills it and relaunches it. I do this to make sure it gets restarted if something goes Terribly Wrong, and also to rotate the log output into the next day&#39;s file. I know I could setup a log rotate entry for it, but I wanted this to be self-contained.</div>






<div><br></div><div>Interestingly, all of the &quot;tee&quot; output seems to be buffered until cron kills the script or the script dies for some other reason. This means I only get one email each day from cron that rolls up all the various errors from that day in a single message. This is actually desirable behavior in this case, but I don&#39;t understand _why_ it&#39;s happening. What if I wanted to be email immediately when an error was detected and also log the error? I&#39;m not seeing anything in my usual reference materials that would explain this behavior.</div>






<div><br></div><div>Any ideas? Is there a better way to to execute this sort of thing?</div><span><font color="#888888"><div><br></div><div>QH</div></font></span></div>
<br></div></div>_______________________________________________<br>
clue mailing list: <a href="mailto:clue@cluedenver.org" target="_blank">clue@cluedenver.org</a><br>
For information, account preferences, or to unsubscribe see:<br>
<a href="http://cluedenver.org/mailman/listinfo/clue" target="_blank">http://cluedenver.org/mailman/listinfo/clue</a><br></blockquote></div><br></div>
<br>_______________________________________________<br>
clue mailing list: <a href="mailto:clue@cluedenver.org" target="_blank">clue@cluedenver.org</a><br>
For information, account preferences, or to unsubscribe see:<br>
<a href="http://cluedenver.org/mailman/listinfo/clue" target="_blank">http://cluedenver.org/mailman/listinfo/clue</a><br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>