Operating System - HP-UX
1834660 Members
2693 Online
110069 Solutions
New Discussion

cron job completion emails

 
SOLVED
Go to solution
Joe Profaizer
Super Advisor

cron job completion emails

I'm getting spammed upon my cron jobs completion. Is there anyway not to have a cron job upon completion NOT email root?

..Joe
4 REPLIES 4
Robin Wakefield
Honored Contributor
Solution

Re: cron job completion emails

Hi Joe,

If the cron job has produced no output, nothing will be mailed, so redirect stdout/stderr to /dev/null, e.g.:

0 1 * * * jobname >/dev/null 2>&1

Rgds, Robin.
Joseph C. Denman
Honored Contributor

Re: cron job completion emails

Robin is correct. When a cron job fails or produces output, an email is sent to root. Redirect your strout and stderr.

...jcd...
If I had only read the instructions first??
Thierry Poels_1
Honored Contributor

Re: cron job completion emails

hi,

cron will send all output (stdout & stderr) to the mailbox of the cron user. You will have to redirect all output yourself if don't want this to fill up your mailbox, as already mentioned.
1 1 * * * job > /dev/null 2>&1 is however not always a good idea, you might miss error messages which you will not be able to review ever.

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Magdi KAMAL
Respected Contributor

Re: cron job completion emails

Hi Joe,

I confirm, with crontab jobs, all standard output and standard error will be sent to the user who had plan the cron job ( because there is no related attached tty to that script ).

If you want to remove all these output ( Standard and error ) you should redirect them to /dev/null.

But attention, sometimes these information are really important to debug some abnormal situation.

If you know about standard output and you assume to redirect to /dev/null, I would PREFER leaving standard error go to the mail so that in case of troubles you will be at least notified for that.

Examples :
1. Redirection of both standard output and standard error :

* * * * * /users/.../script1.sh > /dev/null 2>&1

2. Redirection of only standard output :

* * * * * /users/.../script1.sh > /dev/null

3. Redirection of only standard error:

* * * * * /users/.../script1.sh 2> /dev/null

Good luck.

Magdi