Thanks. Looks like a good place to start.
I have a few questions below ....
On Sunday 27 August 2006 18:03, Shachar Shemesh wrote:
> Aharon Schkolnik wrote:
> > Hi.
> >
> > I need a wrapper for cron jobs that will only send me stdout and stderr
> > if the job failed.
> >
> > I once had a wrapper like this, but I lost it, and can't find it with
> > google.
> >
> > Anyone have one l laying around ?
> >
> > TIA.
>
> I'm programming this into the mail, so totally untested:
>
> #!/bin/sh
>
> OUTFILE=`mktmp -t quiet.XXXXXXX`
>
Woudn't it be better to redirect both stdout and stderr to the same file, in
order to maintain the chronological relationship between them ?
It's up to you, if that's what you want then you can just replace the "2>$OUTFILE.err" by "2>&1".
> if ! "$@" >$OUTFILE.out 2>$OUTFILE.err
> then
> cat $OUTFILE.out
If I understand this correctly, you are redirecting the stderr from the cat
command to its stdout. Is that correct, and what you meant ?
Anything on a cron job's stdout is e-mailed to the owner of the cron job - that's the rule that you are trying to circumnavigate around. Read cron(8).
Maybe you meant to redirect the stdout to stderr ?
cat $OUTFILE.err >&2
Not necessary. Cron will mail both stderr and stdout to the owner.
> cat $OUTFILE.err 2>&1
This redirection is actually redundand - "cat" outputs to stdout anyway and isn't quite expected to write to stderr (unless there is an error in its reading of the file).
> fi
>
> rm $OUTFILE.{out,err}
>
>
> Enjoy
--
The day is short, and the work is great, | Aharon Schkolnik
and the laborers are lazy, and the reward |
is great, and the Master of the house is | [EMAIL PROTECTED]
impatient. - Ethics Of The Fathers Ch. 2 | 050-8724844
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]
--
"Military justice is to justice what military music is to music"
