On Thursday 05 August 2010 12:34, Mark Pace wrote:
>Is there an easy way to make cron not send me an email every time it runs
>one of my jobs? I have one job that runs every 15 mins, and as you may
>imagine that generates a lot of mail. Or is there a way clean up an mbox
>without manually doing it?
Cron will send an email if the cron job generates output (on either of the
standard output or error streams). So the only reason you're getting emails
is because whatever program cron is running generates output.
You can either re-direct the output to the null device, thus throwing it away,
or log it. I recommend logging it. One simple way to do that is with the
logger(1) program, which sends data to syslogd so you're injecting it into
your usual logging mechanism. As an example:
*/15 * * * * myscript 2>&1 | logger -t myjob
That runs "myscript" every 15 minutes, combines its standard error and output
and sends it to syslog tagged with "myjob" using the "user" facility at
the "notice" level. Use logger's -p option to select a different facility or
level if you need to. You can then search the logs for "myjob" to find
output from this cron job.
If you know that "myscript" isn't going to generate any interesting output,
but just want to log any errors, do this:
*/15 * * * * myscript 2>&1 >/dev/null | logger -t myjob
That pipes the error stream into logger, but re-directs the output stream to
the null device.
Hope this helps!
- MacK.
-----
Edmund R. MacKenty
Software Architect
Rocket Software
275 Grove Street · Newton, MA 02466-2272 · USA
Tel: +1.617.614.4321
Email: [email protected]
Web: www.rocketsoftware.com
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
----------------------------------------------------------------------
For more information on Linux on System z, visit
http://wiki.linuxvm.org/