How to Disable or Change the crontab eMail Alert on Linux

Job scheduling is a feature that allows the user to perform specific tasks at a specific time interval.

This reduces the Linux admin job and allows scheduled jobs to run regularly without any human intervention.

By default, crontab email alerts are sent to the “root” user when the job is finished.

If you want to transfer alerts to another user, you have to make the following changes to achieve that.

This can be done in two ways. We will explain one by one in this article.

You can disable alerts for a particular job or disable it completely if you don’t want to receive any alerts.

The crontab configuration file is located in “/etc/crontab” and you are allowed to edit it as a root user.

Go to the following article if you want to schedule a task or job on Linux using crontab.

# cat /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

Method-1: How to Change the crontab eMail Alert Using the MAILTO Option

This is a very simple and straight forward method.

To do so, replace the “root” with your email id and use the sed command instead of manually editing it.

# sed -i 's/root/[email protected]/g' /etc/crontab

Method-2: How to Change the crontab eMail Alert Using the “.forward” File

This is also simplest method, but we do not recommend you to use it.

But we offer a different way to do it. To do so, create a new file named “.forward” under the users’ home directory and add the required email ID.

In my case, I’m going to redirect the root user cron, so I created a file under the “root” directory.

# echo "[email protected]" > /root/.forward

3) How to Disable/Stop eMail Alerts for a Specific Cron Job

If you plan on doing a cron job every five or two minutes, it will be quickly fill your inbox due to frequent mail alerts.

If you want to skip this email alert, you must disable the mail alert for specific cron job.

To do so, add the following value “>/dev/null 2>&1” at the end of the cron job entry.

# crontab -l

0 18 * * * /bin/mysql_backup.sh
0 20 * * * /bin/website_backup.sh
0 12 * * * /bin/offsite-backup.sh
0 21 * * * /bin/offdb-backup.sh
*/5 * * * * /opt/scripts/rsync-backup.sh >/dev/null 2>&1

4) How to Disable/Stop Email Alert Completely for All Cron Jobs

To do so, remove the user ID or mail id from the “MAILTO” option as shown below.

In my case, this is “[email protected]” so I used the following sed command. You need to give the value according to your crontab file.

# sed -i 's/[email protected]/""/g' /etc/crontab

Your output should be identical to below.

# cat /etc/crontab | head -5

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...