bash pipe to log and stderr
Posted on 2005-04-24
I have a bash script that runs and outputs its logging info to $LOGDIR/$LOGFILE. However, if I run it from cron, I want stderr to be sent both to the log file and also to stderr so that I'll get emailed about the problem.
To put it another way, if I output to the log file by doing
doFooStuff >> $LOGDIR/$LOGFILE
then it'll output stdout to the log file and stderr to cron email that I'll get.
If I do:
doFooStuff >& $LOGDIR/$LOGFILE
then it'll output both stdout and stderr to the log file, but I'll never get any cron email.
What can I do? I can't grep the log for error messages because there's no guaranteed string that will indicate an error.
I know that "tee" could somehow be used for stdout. But, I don't want stdout sent in the cron emails. I only want stderr.