<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><div><br></div><div>QH</div></div>