wesupport

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Crontab not sending email – How to solve it

by | Sep 24, 2019

An automated script can save time when doing repetitive tasks.

Cron job comes as a boon while executing tasks at an interval or at a specific time.

However, crontab not sending email is a common error that happens due to incorrect settings in the crontab file.

At Bobcares, we often get requests to fix crontab not sending email as part of our Server Management Services.

Today, let’s get into the details and see how our Support Engineers fix crontab not sending an email.

 

Why CRON Jobs?

Many clients want to perform regular tasks on their servers such as backups, running custom scripts and updating software, etc. However, to perform these tasks manually, it takes more time and effort.

Here, our Support Engineers recommend CRON job to automate such daily tasks. Cron job executes a task at an interval or at a specific time.

Usually, cron works as a time-based scheduler for Linux-based operating systems. So, we can control the minute, hour, day, etc, that it will execute.

Also, each user has their own crontab. To list the cron job of a particular user,

crontab -u USER -l 

Moreover, in order to notify the user whether the command is running successfully, cronjob has a feature that mails the output to the owner of the crontab. It can even send details to the user named in the MAILTO environment variable in the crontab.

To add the MAILTO variable, we add ‘MAILTO=username@domain.com’ into the crontab file.

In cPanel, we can add the MAILTO variable as follows.

 

 

How we fix common Cron job errors

At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers face problems while receiving cron job mails.

Now let’s see the major reasons for cron job-related errors and how our Support Engineers fix the top errors.

 

1. Incorrect settings in the crontab file

Usually, Cron will send the STDOUT and STDERR from the script to email.

Recently, one of our customers had a problem with crontab not sending emails. He had set up a backup script to back up data on his server using an hourly cron.

On checking, our Support Engineers found that he had set up script in a way to redirect output to a file. So there wasn’t any data to send. Therefore, we tweaked the settings in the crontab file as:

0 * * * * script.sh >> /var/log/script.log

This started logging the output to the log file and sending the error messages to the email.

 

2. Missing email address

Similarly, many customers experience the problem of crontab not sending email because of the wrong email address assigned to ‘’MAILTO=”. The crontab can’t send email to the mentioned email address without having a proper email server.

Also, if the email address provided is incorrect as it contains typo mistakes, the email sending fails.

In addition, the crontab allows you to set up MAILTO=root, then the mail will automatically be sent to the default email address of the root user.

In one of the servers, the customer has specified an invalid email address in the .forward file. As a result, all root mails failed including the mails from the crontab too.

So, our Support Engineers logged in to the server as a root user and added the correct email address to /root/.forward file there.

That solved the problem and mail started working fine.

 

[Need assistance to fix cron job errors? We’ll help you.]

 

Conclusion

In short, crontab not sending email error can happen due to missing root mail forwarder or due to the bad settings in the crontab file. Today, we saw the topmost reason for the cronjob errors and how our Support Engineers fixed it.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

6 Comments

  1. Gökhan Demir

    I had this problem on a server. There was no redirections, and MAILTO addresses were correct, no typos etc.

    I managed to resolve this only by force reinstalling cronie. Server was Centos 7.

    yum reinstall cronie

    Reply
    • Sijin George

      Yes, the package reinstall also helps at times. But special care must be taken while reinstalling.

      Reply
    • Swati

      Hi

      When we get the smtp details from database then cron job is not working. Can you please advise what to do.
      Thank you

      Reply
      • Hiba Razak

        Hi,
        Please contact our support team via live chat(click on the icon at right-bottom).

        Reply
        • Muthalagusekar

          When we scheduling via cron job mail is not sending

          when we run manually its working fine

          Reply
          • Hiba Razak

            Hi,
            Our experts can help you with the issue.we will be happy to talk to you through our live chat(click on the icon at right-bottom).

Submit a Comment

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

Categories

Tags