Solaris cron job email generation not required

Hi,

How do we stop default cron job emails bein generated in Solaris 10?

All our cron entries are ending with /dev/null 2>&1 but still emails are being generated.

And all these emails are nuisance, as they are also get relayed to our local network sendmail MTA server (for system email alerts) and overwhelms it.

Everyday we have to delete 50,000+ email queue on our local network sendmail MTA server which is not the right way to run IT operations.

You should probably try to identify and fix the root cause instead of trying to alter a standard behavior.

Why are your cron jobs generating output while asked not to ?

Can you post a sample crontab entry that exhibit the problem ?

you could try enclosing your commands and redirecting to /dev/null (i.e., * * * * * * (some_script) > /dev/null 2>&1 ) or you could actually go into each script and redirect all unnecessary message outputs (i.e. " rm -f /dir/file 2> /dev/null ") as well as comment out all unnecessary echo lines (i.e., " # echo 'i am here' ) ...

Are you cron entries ending /dev/null 2>&1 or > /dev/null 2>&1 ?

Without a re-direct for standard output, you are just passing /dev/null as a parameter and redirecting standard error to standard out, which will still generate an e-mail.

It might just be a typo though........

Robin

hi all,
Im hasan.kamali's team member.
here is one of the cron entry which is generating email.
1,4,7, * * * * /med/appl/orbix2/BusinessMediation/bin/start_mediationsocket_servers > /dev/null 2>&1.

and the total script count is in hundreds and it is impossible to reevaluate each single script and add > /dev/null 2>&1 this at the end of lines.

Okay, well the re-direction appears to be okay, but I presume it is writing to a different file-descriptor then. If it is code you can read, is there anything that does a >&3 , or perhaps 4, 5 .... that might be causing the e-mail. You may end up suffixing your cron records like this:-

1,4,7 * * * * /your-script > /dev/null 2>&1 3>&1 4>&1 5>&1 6>&1 7>&1

I must say that it seems an odd definition to run a command on the first, fourth and seventh minute of every hour. It this really it? Well, there must be a need for it. Do you really have:-

  • A comma at the end of 1,4,7,
  • A full stop at the end of the record as in 2>&1.

They could be confusing things too I suppose.

What do you get if you run these on the command line? If you get output, then cron will always e-mail you. I'm assuming that the purpose of the script is not to send an e-mail, of course.

Robin

run this one as the crontab user ...

crontab -l > /tmp/file
grep -v "/dev/null" -n /tmp/file > /tmp/noredirect

check /tmp/noredirect for the offending entries ... if /tmp/noredirect is empty, re-grep using "> /dev/null" as the search string ...

What contain these mails ?
Please post a sample including headers.

Hi,

I have executed the code mentioned below:
crontab -l > /tmp/file
grep -v "/dev/null" -n /tmp/file > /tmp/noredirect

and found multiple entries in cron which do not end with '/dev/null'.

And here is the sample email generated by cron:

Your "cron" job on mercury2
/export/home/orbix2/medcamtel.ksh >> /export/home/orbix2/logs/medtel.log 2>>/export/home/orbix2/logs/medtel.log

produced the following output:

! could not obtain latest contract for PID 11571: No such process Thu Jun 27 09:09:00 2013

Well, the cron record looks okay, but something inside the code must be writing to an output file descriptor other than &1 (Standard Output) or &2 (Standard Error)

Can you (without compromising yourself security-wise) post the script?

Robin

yes robin i will definately do that but first let me put '/dev/null' at the end of each and every cron entry.

Are you proposing to therefore stop writing your logs to /export/home/orbix2/logs/medtel.log (in this case)

The problem is output that is not being directed to a file gets sent as an e-mail. You might be losing valuable trace information if you just throw it all away, including whatever you are logging in /export/home/orbix2/logs/medtel.log so far.

Robin

try enclosing the offending line and redirect its output to /dev/null ... this way you do not have to do anything with the scripts at all until you have enough time to do so ... btw, i shortened the original line n the sample as both your stdout and stderr are being redirected to the same file ...

(/export/home/orbix2/medcamtel.ksh >> /export/home/orbix2/logs/medtel.log 2>>&1) > /dev/null 2>&1

The root cause is unlikely due to missing redirections. The error message sent is from cron itself, not the scripts.

What OS version are you running ? (cat /etc/release)
What user's crontab is affected ?

if possible, run this by itself and see if you get the error reported by cron ...

/export/home/orbix2/medcamtel.ksh >> /export/home/orbix2/logs/medtel.log 2>>&1

if you do get the error still, make sure you fix the redirection ... if you do not get the error, check /var/adm/messages for any errors around the time the cron job runs ....

btw, just saw this and this ... it seems the could not contain latest contract issue is related to a bug in cron. workaround is to redirect output ...