Linux | Manage emails of Cron Jobs

|
| By Webner

Stop sending cron job email notification & managing the notifications.

We mostly use cron jobs for recurring tasks like batch payments, server startup/shutdown, system updates etc. Most of the cron jobs send email notifications. If you want to stop those notifications or want to send notifications to specific users then below are the few methods that can help in managing the notifications according to your requirements.

1. When you want to send notifications to specific email addresses:

Define following property in /etc/crontab
MAILTO=””
If you put email id or ids, then the notification will be sent to those users, if left blank then there will be no notification.

2. Disable email notifications: Add the following at the end of every scheduled task for which you want to disable notification:

/dev/null 2>&1

For Example: 0 22 * * * root sh /opt/tomcat/shutdown.sh >/dev/null 2>&1

3. Send Cron notification to System Logs rather than sending emails or suppressing the output:

Edit vi /etc/sysconfig/crond, and put the below line at the end of file:

CRONDARGS=-s -m off

Run restart command to restart crond service:

shell> systemctl restart crond.service

Explanation of above command:

-s means it will send the notification to the system logs.
-m this argument will disable cron service from sending emails notification.

Leave a Reply

Your email address will not be published. Required fields are marked *