1848581 Members
3073 Online
104033 Solutions
New Discussion

Cron settings

 
SOLVED
Go to solution
Noa Harel_1
Occasional Contributor

Cron settings

Hi,
I want to prevent the cron from sending e-mail to the root users when ever activating a cron scheduled job.
Thanks guys
5 REPLIES 5
Robin Wakefield
Honored Contributor

Re: Cron settings

Hi Noa,

cron will mail any output to the user that invoked it, so you need to make sure your cronjob produces no output. Either redirect the stdout + stderr to /dev/null or a log file on the cron line itself, or, if you're calling a script, within the script itself.

Rgds, Robin.
Santosh Nair_1
Honored Contributor
Solution

Re: Cron settings

You can redirect the output of the cronjob to /dev/null, i.e.

m h D M W /some/cron/script >/dev/null 2>&1

where m = minute, h-hour, D=day, M=month, W=days of week. The 2>&1 will redirect stderr to stdout and >/dev/null will direct stdout to /dev/null. Hope this helps.

-Santosh
Life is what's happening while you're busy making other plans
Dave La Mar
Honored Contributor

Re: Cron settings

Santosh has the answer. I was plagued by this as well.
Sample crontab entry -
0 19 * * * /opt/apps/jobprod/backup/jdaprod_splitb

c/jdaprod_splitbc >/dev/null 2>&1

Best of luck.
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Tom Maloy
Respected Contributor

Re: Cron settings

One other note: order is important.

The correct order, as shown in earlier replies, is:

> /dev/null 2>&1

You must first redirect stdout, and THEN redirect stderr to stdout. Real easy to get it backwards, and then wonder why it doesn't work...

Tom
Carpe diem!
Noa Harel_1
Occasional Contributor

Re: Cron settings

Thank's
I wrote the syntax wrong before.
Now It's working!
Thanks