1831387 Members
3553 Online
110025 Solutions
New Discussion

cron without email ..

 
SOLVED
Go to solution
someone_4
Honored Contributor

cron without email ..

Hey everyone
Is there a way to fix a cron job so it does not send an email to root's email? Or is there a way to send it to someone elses email?
Thanks

Richard
3 REPLIES 3
eran maor
Honored Contributor
Solution

Re: cron without email ..

Hi

Cron will always automatically mail output for stdout
and stderr to root unless you specifically state in the
command that stdout and stderr are redirected elsewhere.

To disable cron from mailing output to root add the following to the end of the
cron entry:

> /dev/null (this redirects std. out to the bit bucket)

2> /dev/null (this redirects std. error to the bit bucket)

> /dev/null 2>&1 (this redirects both std. out and std. error)

Here are a couple of examples:

0 1 * * * /path/command [options] > /dev/null


0 1 * * * /path/command [options] > /dev/null 2>&1
love computers
Sanjay_6
Honored Contributor

Re: cron without email ..

Hi Richard,

If you want to forward all the mails sent to root to another user you can specify that in the mail alias. Set another mail id for and alias named root. In some of my systems an alias is set where all mail to root are forwarded to my email address. This way all cron messages will be forwarded to that email address.

Hope this helps.

Regds
Patrick Wallek
Honored Contributor

Re: cron without email ..

Richard,

I've been trying for 2 days to respond but the Forums Gods were apparently against me!

Anyway, here is what I do to redirect cron job output to a different e-mail address:

00 14 * * 5 /dir/to/cron/script 2>&1 | mailx -s "Output from /dir/to/cron/script" youaddress@mail.com

That redirects standard out to standard error and pipes it all to mailx to mail it to you. Works pretty well. The examples Eran gave you work if you don't want any messages.