Solving the “Crontab Not Sending Email” Error

Solving the “Crontab Not Sending Email” Error

When you have a mundane, repetitive task at hand, it’s best to make use of an automated script. Behind the scenes, that’s what Cron does. It is programmed to automatically execute tasks at a particular interval or specific time.

But when the tasks don’t match how it is configured, then Cron doesn’t work as it is supposed to. And one of the most common error you’re going to come across is the Crontab not sending you emails about the task output. This hinders your ability to know whether or not the automated Cron scripts were successful. In this article, learn how to fix this error in a few steps.

What are Cron Jobs?

Cron jobs are scripts that you set and are meant to perform repetitive jobs at a scheduled time frame.

Think of running a complete server backup everyday after 2 AM when all the staff members are done with their work. With Cron job, you don’t have to stay late until 2 AM everyday. You can set Cron and get to sleep by 10 PM.

Cron works as a time-specific scheduler for Linux servers and operating system. You can control the hours and minutes it will execute.

Every user at your organization will have a Crontab or Cron table assigned to him. You can list the cron job for that particular user using this command -
Code:
crontab -u USER -1
Cronjob will further mail the output of a particular command to the admin. It will help you ensure things are working correctly.

Furthermore, it can also send these details to the user whose name is listed on the MAILTO environment variable.

For adding the MAILTO variable, you need to open the crontab file and add “MAILTO=user1@domain.com”.

You also have the option of adding MAILTO in cPanel. Go to Cronjob directory and update the email.
cron.png


Fixing Crontab Not Sending Email Error

At times, you’ll notice that Crontab is not sending the email notification as it is intended to. More often than not, the problem lies in the settings.

Usually, Cron sends out two things from the script to the email, namely, STDOUT and STDERR.

In some cases, instead of backing up data on an hourly basis using Cronjob, you might have configured it to something else -- say logging in errors to the scripts.log file. If there’s no error, Cronjob will not send any emails to you because there will be nothing to send.

So as a first measure, you should check if you’ve set up Crontab properly for that user.

Email Address Not Specified

This is one of those “How-Could-I-miss-that” error where you forgot to specify the email address. Or you might have specified a wrong email address.

You need to check the “MAILTO=” parameter. To send the email successfully, Cronjob will require a proper email server and email address. Both of these should be correct with no typo errors.

You also have the option of setting “MAILTO=root”. In this setting, Cronjob will send the emails to the default email address of the root user.

So that’s how you fix the Crontab not sending email error. In case of further assistance, contact your hosting provider.
Author
kumkumsharma
Views
192
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top