[ale] cron mail, how to STOP it.
Geoffrey
esoteric at 3times25.net
Sat Oct 15 09:47:17 EDT 2005
James P. Kinney III wrote:
> On Fri, 2005-10-14 at 20:58 -0400, Geoffrey wrote:
>
>>Paul Cartwright wrote:
>>
>>>I created a cron entry to check my yahoo mail using yosucker. I HATE
>>>getting emailed every X hours to tell me it ran... I "thought" the
>>>correct way to stop the mailing of a cron job running was to add a
>>>2>/dev/null at the end of the line.
>>>here is the line I don't want mail from:
>>>10 3,6,9,12,15,18 * * * /home/pbc/bin/yosucker
>>>
>>>
>>>suggestions?
>>
>>10 3,6,9,12,15,18 * * * /home/pbc/bin/yosucker >/dev/null 2</dev/null
>
>
> This will send all output of the yosucker command to /dev/null.
> The cron process _still_ has an automatic email built it that can only
> be disabled by the aforementioned
> MAILTO=""
> line at the top.
I would disagree. MAILTO works, I agree. But, if there is no output
produced by the script, no mail goes out.
For example, the following cron entry says email, both stdout of the
'date' command and the stderr of the non-existen 'dte' command to my email:
* * * * * date ;dte
However, the following executes without sending any email:
* * * * * date > /dev/null ;dte 2>/dev/null
> Of course this brings up the obvious, "What if I want _some_ crons to
> notify me and other to not waste my time?"
> Tough cookies. It's an all or nothing deal. There are some other cron
> beside the standard Vixie cron that might support that. I have not used
> any of them. I use wrapper scripts that handle email notification for
> those jobs I need notification of and turned off the cron notification
> by default.
If you want the output, whether it be stderr or stdout to go elsewhere,
it can be redirected in the script:
exec 2>/tmp/stderr
exec >/tmp/stdout
or
exec 2>/dev/null
or other some such.
You can also created additional file descriptors in shell as such:
exec 3>/tmp/dateoutput
date >&3
The above works in both bash and ksh.
And of course you can redirect anything to the mail command from within
the script.
There are a lot of things you can do to control the output of a cron job.
--
Until later, Geoffrey
More information about the Ale
mailing list