LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Stop Cron from sending email (http://www.linuxquestions.org/questions/linux-server-73/stop-cron-from-sending-email-925461/)

buee 01-24-2012 09:27 AM

Stop Cron from sending email
 
I have a CentOS based e-mail sever that runs a bunch of cron jobs. The problem I'm having is that cron is sending emails as logs and that seems to be cluttering things up. The e-mails are entering loops between the server itself and the Barracuda SPAM filter that we have, then it times out. Each e-mail loop causes ~15 log entries and each cron job runs every 5 minutes 24x7. The math isn't important, but it's a ridiculous amount of logging. I would like to stop cron from sending email completely, but can't find it. I would like to have cron output to just a local log file if possible.

TenTenths 01-24-2012 09:58 AM

Did you even bother to google it?

http://www.cyberciti.biz/faq/disable...ontab-command/

MartinStrec 01-24-2012 10:01 AM

Edit '/etc/crontab'

set MAILTO variable to empty

MAILTO="" or MAILTO=

Probably a better way is to edit the script that is responsible for sending the mails, e.g. /etc/cron.hourly/a-script

and there redirect the output of error messages to the null device
/path/to/command -parameters >/dev/null 2>&1

buee 01-24-2012 10:11 AM

@TenTenths:
Yes, I did, and I followed a link to a similar answer. I guess my question should've been "How do you universally disable cron from sending email?" rather than disabling emailing for particular cron jobs

@MartinStrec: Basically, see above. I followed your methods, but I'm looking for a universal way of telling cron "just don't send e-mail" or "output to file rather than email"

TenTenths 01-24-2012 10:16 AM

Quote:

Originally Posted by buee (Post 4583200)
@TenTenths:
Yes, I did, and I followed a link to a similar answer. I guess my question should've been "How do you universally disable cron from sending email?" rather than disabling emailing for particular cron jobs

Sorry for my sharp response, I'm tired and forgot my first rule of never post when tired. On the example from google and Martin the MAILTO variable is your friend in this particular case. I make extensive use of it and then use other methods such as having any cron script I use do its own logging or sending of e-mail alerts.

MartinStrec 01-24-2012 10:20 AM

Also you can modify argument for crond

edit /etc/sysconfig/crond
(I guess it is the same in your distribution)
and use CRONDARGS variable to set what ever you want

see 'man crond' manpage for all arguments

I guess you expect CRONDARGS="-s"
( -s This option will direct Cron to send the job output to the system log using syslog(3). )

Reuti 01-25-2012 05:54 AM

It would indeed be an option to set it in the configuration file, but it depends whether you have the original vixie-cron where itís not available AFAICS, or cronie. man cron should reveal it.

ranamalo 10-01-2012 02:27 PM

Solution
 
Background info that may help people:
CentOS 6 runs cronie
CentOS 5 runs vixie-cron

In CentOS6 cron's default behavior is to send an email to the owner of the cron job if the cron job produces any output (stdout or stderr). If the flag: MAILTO is present and has a value (in crontab or elsewhere /etc/cron.d for example) any output will be emailed the the email specified after MAILTO.

To turn off emailing use the flag -m off in /etc/sysconfig/crond:

# Settings for the CRON daemon.
# CRONDARGS= : any extra command-line startup arguments for crond
CRONDARGS='-m off'

And restart crond

# /etc/init.d/crond restart


All times are GMT -5. The time now is 11:43 AM.