Sunday, March 25, 2018

Stop Cron and Anacron job 'cron.daily' Family of emails

The standard solution to the cron daemon sending emails to root is:

  • For each cron job in crontab (accessed via "crontab -e"), redirect standard output and standard error to a file or to null, for example:
    0 5 * * 1 tar -zcf /var/backups/home.tgz /home >/dev/null 2>&1
  • Add the following to crontab before the cron jobs list:
    MAILTO=""
However, this still leaves Anacron to send emails with subject lines like "Anacron job 'cron.daily' on node foobar" every day, week and month. To get around this, edit /etc/anacrontab using your usual favorite editor and add MAILTO="" before the Anacron jobs list.

Here is an actual complete /etc/anacrontab:


# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root
MAILTO=""

# These replace cron's entries
1       5       cron.daily      run-parts --report /etc/cron.daily
7       10      cron.weekly     run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly    run-parts --report /etc/cron.monthly


This works on Ubuntu 14 and Ubuntu 17, and should work on all Anacron-enabled Unix and Linux systems.

No comments:

Post a Comment

"SEO" link builders: move on, your spam link will not get posted.

Note: Only a member of this blog may post a comment.