3 Ways to Stopping Emails from Cron Daemon

3 Ways to Stopping Emails from Cron Daemon

Cron Daemon is a handy tool for scheduling tasks. It also sends out emails to notify the users about the developments. But at some point in time, you may get excessive emails from cron jobs. So much email can get overwhelming to manage or even read. In such cases, it’s best to stop the emails from coming.

There are several ways you can do that. In this article, learn about the three ways you can stop emails from Cron Daemon.

What are Cron Daemon Emails?

Linux offers the Cron system command to schedule tasks that are automatically executed at given intervals. It’s a great way to ensure scripts run at specific times without manual intervention.

When you set up Cron jobs, you’d have to specify time interval, a user who’d be running the command, and the command itself.

Cron will then send emails to the user about the result of the execution. If you’re the user, you’ll get the output and errors of the job in the email. Things get out of hands when Cron runs many commands for that particular user. So you may get an excessive number of emails.

php-cron.jpg


How to Stop Excessive Cron Daemon Emails?

As already mentioned, there are more than one ways to stop overflow of emails from Cron jobs. Here are three ways you can follow:

Change the MAILTO variable

Crontab will send emails of the results to emails mentioned in the MAILTO variable. By default, it’s set to root. So the root user will get all the emails. If left unchanged, the root user will be bombarded with all the emails from Cron. To avoid this, you need to change the variable to something else.

So navigate into /etc/crontab file and find the MAILTO=‘’ variable. Then reset it to blank. It will disable all emails from Cron daemon.

Redirect errors and outputs to null

Another way to disable the mail alerts from Cron is by redirecting the output and error to null. If you want to disable notification for a specific crontab entry, you can redirect the outputs to /dev/null like this:

Code:
/dev/null 2>&1
It’d disable all the output messages.

While this method is easy, it’s not recommended. Doing so will disable all the error messages as well. This will make debugging and troubleshooting much harder.

Configure crond

The third way to stop emails is to configure ‘crond’ and disable the mail feature. To locate the file, navigate into /etc/sysconfig/crond and edit the CRONDARGS string.

Code:
CRONDARGS= -s -m off
Including the ‘-s’ argument will direct the output to the system log. In this way, you can have a log of outputs and errors. The ‘-m’ argument prevents crond from sending output emails.

Now you will not get emails regarding Cron job and still have a log of errors.

So, that’s how you stop cron emails. Select the method that best suits your requirements. For further assistance, contact the hosting support team.
Author
kumkumsharma
Views
3,864
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top