[clue] tee in cronjob

Quentin Hartman qhartman at gmail.com
Mon May 19 17:32:33 MDT 2014


I hadn't considered that the while loop opens a subshell, that's almost
certainly it.

Thanks!

Q


On Mon, May 19, 2014 at 5:20 PM, Mike Nolte <obiwanmikenolte at gmail.com>wrote:

> QH,
>
> I'm a little unclear on the specifics, but a "while" loop opens a
> subshell, which could be why it's being buffered.  You could use a for
> loop, use redirection instead of tee (>>), or something like that.
>
> ~Monkeypenny
>
>
> On Mon, May 19, 2014 at 5:09 PM, Quentin Hartman <qhartman at gmail.com>wrote:
>
>> I have a script that looks roughly like:
>>
>> now=`date +%F`
>> logfile = log-$now.log
>> while [ 1 -eq 1 ]
>> do
>>  things
>>   if [ $? -ne 0 ]
>>   then
>>    echo "Oh noes!" | tee -a $logfile
>>   fi
>> done
>>
>> And it'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's file.
>> I know I could setup a log rotate entry for it, but I wanted this to be
>> self-contained.
>>
>> Interestingly, all of the "tee" 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't understand _why_ it's happening. What if I wanted to
>> be email immediately when an error was detected and also log the error? I'm
>> not seeing anything in my usual reference materials that would explain this
>> behavior.
>>
>> Any ideas? Is there a better way to to execute this sort of thing?
>>
>> QH
>>
>> _______________________________________________
>> clue mailing list: clue at cluedenver.org
>> For information, account preferences, or to unsubscribe see:
>> http://cluedenver.org/mailman/listinfo/clue
>>
>
>
> _______________________________________________
> clue mailing list: clue at cluedenver.org
> For information, account preferences, or to unsubscribe see:
> http://cluedenver.org/mailman/listinfo/clue
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue/attachments/20140519/bf8b9bda/attachment.html 


More information about the clue mailing list