Bobcares

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 *

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

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF