Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SOLVED Cron job stopped sending emails

Discussion in 'E-mail Discussion' started by david364, Nov 19, 2017.

  1. david364

    david364 Active Member

    Joined:
    Sep 15, 2013
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    I'm running a script in cron that sends email using smtp and a socket, and it was working until I upgraded OS, WHM, and cPanel about a month ago. Now it doesn't send email (run from cron) and doesn't cause an error in any log (cron, PHP, Apache). It seems to be run under the correct user and in the correct working dir. I'm stumped. It works when run directly in the browser address bar, either locally or remotely, but not under cron.
     
  2. SysSachin

    SysSachin Well-Known Member

    Joined:
    Aug 23, 2015
    Messages:
    604
    Likes Received:
    42
    Trophy Points:
    28
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Twitter:
    Can you please provide your cron details.

    Give command

    crontab -l -u username
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. david364

    david364 Active Member

    Joined:
    Sep 15, 2013
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    I do not know where the crontab command is in my system. I provide the command "php -f /home/nsr/public_html/mon-m3maje.php" using cPanel. I am not expert with Linux, although I've learned a lot about it and WHM and cPanel. I am a Windows programmer since 1994.
     
  4. rpvw

    rpvw Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    691
    Likes Received:
    233
    Trophy Points:
    93
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. david364

    david364 Active Member

    Joined:
    Sep 15, 2013
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    No, I see no help there. The command "php -f PATH" should work, and did work before the upgrade. There seem to be some new bugs in cron that have not yet been fixed. But I am not sure if they are the cause of the problem I am describing here. I am investigating further by instrumenting my php program.
     
  6. rpvw

    rpvw Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    691
    Likes Received:
    233
    Trophy Points:
    93
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    Following your updates, you may need to be calling the absolute path for whatever php binary you use for that domain.

    If you let us know what EasyApache you use, and which PHP handler and version, and which cPanel you have installed, we might be able to make an educated guess at what your cron command should be.

    You have marked yourself as a Reseller Owner - you probably want to ask whoever you get your reseller package from; what the path to the php binary you use on that domain should be.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #6 rpvw, Nov 20, 2017
    Last edited: Nov 20, 2017
  7. david364

    david364 Active Member

    Joined:
    Sep 15, 2013
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    No documentation says that php -f PATH no longer works. That makes no sense. It should use the default version of PHP. The installed WHM documentation says that both the default and specific version commands work.

    See known EasyApache bug list at Current Status of EasyApache 4 - EasyApache 4 - cPanel Documentation
    See also bug report at CLI not recognized in cron jobs

    I plan on instrumenting my test case to learn more. Please standby with suggestions until I have more information, thanks.
     
  8. rpvw

    rpvw Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    691
    Likes Received:
    233
    Trophy Points:
    93
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    OK, Sorry for bothering you and trying to help.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. david364

    david364 Active Member

    Joined:
    Sep 15, 2013
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    As a long-time software engineer, I reserve the right to insult without realizing, and in general not understanding tact.
     
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,928
    Likes Received:
    1,819
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Have you reported this issue to your reseller hosting provider so they can take a closer look and verify if they've made any changes to the PHP configuration or handler on the system? Note you should follow the PHP command example referenced in the following post when setting up cron jobs:

    CLI not recognized in cron jobs

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. david364

    david364 Active Member

    Joined:
    Sep 15, 2013
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Cron should be able to execute standard commands like "php -f PATHNAME" and not require that a particular version of PHP should be specified.

    Indeed, when I found the problem the cron job is now working again.

    The problem was the same in all three versions of PHP: the allow_url_fopen directive in the php.ini file, which is supposed to be enabled by default, was disabled (as seen in the WHM multi php editor). This caused a "file_get_contents" function in my programs to return NULL or an empty string, which in turn made the program skip the part where it sends email.

    Here is a short test program anyone can use to detect the problem:

    Code:
    <?php
    $URL="http://removed";
    $Contents=@file_get_contents($URL);
    echo "Contents of $URL as read by file_get_contents:<br>";
    echo $Contents;
    echo "<br>";
    ?>
    This test program still fails when run in a browser: "removed/test.php" . But my cron job is once again sending me appropriate emails.

    Thank you all for being patient while I figured this out.
     
    #11 david364, Nov 20, 2017
    Last edited by a moderator: Nov 21, 2017
  12. david364

    david364 Active Member

    Joined:
    Sep 15, 2013
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    After a graceful reboot of my server, the test program t.php seems to run correctly in a browser.

    Consider this thread closed, with a possible WHM bug discovered.
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice