Results 1 to 20 of 20

Thread: cPanel Cronjob?

  1. #1

    cPanel Cronjob?

    Hello

    A customer of mine wants to use the cPanel cronjob. He set something to run about every 5 minutes but the script doesn't get executed. He's executing a PHP script using the "php -q /home/USERNAME/filename.php > /home/USERNAME/debug.txt" command.

    Does SSH has to be enabled in order for the cron to work or something? I have no idea what the cause of this is.

    Thanks

  2. #2
    I am pretty sure SSH has to be enabled with cPanel accounts...

  3. #3
    SSH not necessary for runing cronjobs. You user must to configure cron properly from his cPanel.
    If you are root on the server, please, show this users's cron file.
    /var/cron/USERNAME

  4. #4
    I'm sorry for the delay:

    0 * * * * /usr/local/bin/php -q /home/USERNAME/www/WriteLog.php > /home/USERNAME/crondebug.txt

    That's it
    Aything strange with that?

    Btw is that thing executed as root or under the username's account?

  5. #5
    Join Date
    Nov 2004
    Location
    India
    Posts
    1,100
    Is this path is correct '/usr/local/bin/php '? also check the '/var/log/cron ' cron log file..
    AssistanZ - Beyond Boundaries...
    Cloudstack Consultancy / 24x7 Web Hosting Support / 24x7 Server Management / Infrastructure Management Services
    Web & Mobile Apps Development / Web Designing Services / Php, Grails, Java Development

  6. #6
    Join Date
    Feb 2005
    Location
    I am air u breathe
    Posts
    229
    Hi there,

    Also try running the script directly from the shell and check if there is any trouble with the program.

    Al
    It is reliability that counts...
    Few tips

  7. #7
    Running the script directly from the shell gives no problems, I already tried that.

    Yes, the path to PHP is correct.

    I did a search for his username in the cron log file but all I could see is stuff like this:

    Jun 11 17:51:19 server crontab[12496]: (USERNAME) LIST (USERNAME)
    Jun 11 17:55:17 server crontab[12912]: (USERNAME) REPLACE (USERNAME)
    Jun 12 15:16:35 server crontab[27564]: (USERNAME) BEGIN EDIT (USERNAME)
    He also tried it using crontab -e...

  8. #8
    Join Date
    Mar 2004
    Location
    New Jersey
    Posts
    793
    Set it up to run every five minutes?
    Code:
    0 * * * * /usr/local/bin/php -q /home/USERNAME/www/WriteLog.php > /home/USERNAME/crondebug.txt
    I know it's late here, and I just migrated a crapload of CentOS servers to 3.5, but isn't this supposed to be:
    Code:
    */5 * * * * /usr/local/bin/php -q /home/USERNAME/www/WriteLog.php > /home/USERNAME/crondebug.txt
    What you have I believe is set to run at every MINUTE ZERO of every hour, no? It's late... could be wrong.

  9. #9
    Join Date
    May 2004
    Posts
    1,663
    [i]What you have I believe is set to run at every MINUTE ZERO of every hour, no? It's late... could be wrong. [/B]
    I believe you are right .

  10. #10
    Hmm ok I set it to 5 minutes, but still not working...

  11. #11
    Join Date
    May 2003
    Location
    Kirkland, WA
    Posts
    4,448

  12. #12
    Join Date
    Feb 2005
    Location
    I am air u breathe
    Posts
    229

    Thumbs up

    Have you tried providing a valid mail address to the cron job via cpanel. This does give the error that appears while executing the script.

    Hope this helps.

    Al
    It is reliability that counts...
    Few tips

  13. #13
    Join Date
    Sep 2002
    Location
    Top Secret
    Posts
    11,686
    Firstly, it's entirely possible that the script is bad itself, which will cause the cron to just bail.

    Secondly, you'll most likely find the problems not in the error log specified, but in the user's email. By default (unless cron has been told to set MAILTO somewhere else), the user calling the script gets mail every time this is run. Have them check their mailbox. Not their addon accounts, but the main account.

    If the user is using a "jailshell" instead of bash, or whatever, then this could cause a problem as well. Unfortunately, if this is the case, the only solution here may be to allow them access to the shell in order to run their script, as jailshell is not bash, it's a replacement for it, and many things can't be used inside of a jailshell environment.

    Have the user login, run the script from ssh, see what errors it produces. Most likely you'll have the problem solved when you do that.
    WHMCS Guru - WHMCS addons, management, support and more.
    WHMCS Notifications Extended - Add slack, hipchat, SMS, pushover to WHMCS !!
    Always looking for Linux, WHMCS, Support Desk work. PM for details

  14. #14
    Ok I did some more testing, but whatever I do, I can't get it to work. I made a simple test script in PHP which sends me an e-mail every time it gets executed:

    Code:
    <?
    	mail("*********", "Cron Executed", "Cron executed @ ".date("l dS of F Y h:i:s A").".");
    ?>
    When executing the script via the browser, it works. I added the following line via cPanel in the crontab of my user (which has shell access, non-jailed):

    Code:
    * * * * * /usr/bin/php -q /home/****/public_html/cron.php
    when I execute that line in the shell (as that user) it works. Same for when executing as root, offcourse. However, I don't get ANY emails automatically thanks to the Crontab. Also, I don't get any cron e-mails (but that is maybe cuz the script doesn't have any output, however).

    So, I removed that line from the crontab and logged in as root and added the line in the main cron (using crontab -e command). Same thing, I don't receive any emails, the cron doesn't get executed.

    This is really strange and I have no idea what is happening here

    AND!! What I also noticed today is (the server is a bit new): in WHM, the "CPU/Memory/MySQL Usage" doesn't list anything. Not for any month so far. I noticed the following line in the "crontab -e" and guess that this script is supposed to be executed so that the CPU/Mem/MySQL gets logged:

    Code:
    */5 * * * * /usr/local/cpanel/bin/dcpumon >/dev/null 2>&1
    Seems like that doesn't get executed either, right?

    Then what the hell is the problem Why isn't there any cron being executed on my server?? Help please!

    Thanks

  15. #15
    Join Date
    Sep 2002
    Location
    Top Secret
    Posts
    11,686
    * * * * * /usr/bin/php -q /home/****/public_html/cron.php
    Double check your environment. In the later installations, the path is /usr/local/bin/php , not the other. Also, make sure that mail is compiled into php, pretty easy there.

    As well, check to make sure that cron is in fact running .
    Code:
    ps xua | grep cron
    as root will do that. If you see cron in there, then it's running.
    WHMCS Guru - WHMCS addons, management, support and more.
    WHMCS Notifications Extended - Add slack, hipchat, SMS, pushover to WHMCS !!
    Always looking for Linux, WHMCS, Support Desk work. PM for details

  16. #16
    Yep I checked it. If I run the command like that in the shell it works, so it should work too as cron, right?

    Anyway the problem is probably that cron is not running, as I don't see anything when I execute that command. :\

  17. #17
    I restarted cron and it seems to be working...

    I wonder why cron wasn't running for such a long time. Can crond crash or something?

  18. #18
    Join Date
    Sep 2002
    Location
    Top Secret
    Posts
    11,686
    Then restart it
    Code:
    service crond restart
    will do that
    In addition, you may want to take a look @ this thread for an idea on how to ensure that your cron is running all of the time.
    <edit>
    Make SURE to read the whole thread, I posted two versions of the code, the second is better, more efficient
    </edit>
    WHMCS Guru - WHMCS addons, management, support and more.
    WHMCS Notifications Extended - Add slack, hipchat, SMS, pushover to WHMCS !!
    Always looking for Linux, WHMCS, Support Desk work. PM for details

  19. #19
    Thanks I will check it out later today (first have to fix some more things).

    Thanks alot for all your help people.

  20. #20
    The Planet support also told me this btw:

    There was one additional step needed before I would close this ticket though.

    crond was not setup to start on boot of your server. This happens every once and a while when Redhat pushes out new updates and new init scripts are not added back in.
    Just so you know, if it ever happens to you...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •