Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jul 2007
    Posts
    11

    Default PHP script as Cron job

    I want to execute a php script regularly, and for that reason I created a cron job through WHM. The file is indeed executed, but it fails to do so correctly. I receive this error:

    /home/site/cron.php: line 1: ?php: No such file or directory
    /home/site/cron.php: line 3: =: command not found
    /home/site/cron.php: line 4: =: command not found

    etc.

    After searching I find this has to do with the format of the script. I wrote this as if it is made for usage through a browser, but now I read that it should be adapted in order to work as a cron. However, I can not find how to change this. Anyone any ideas?

  2. #2
    Member
    Join Date
    Nov 2001
    Location
    Athens - Greece
    Posts
    98

    Default

    Your cron entry for the script should be something like:

    0 0 * * * php /home/site/cron.php

    which will execute with php the script /home/site/cron.php every day on 00.00 exactly.
    ------
    CPanel Tips and Solutions
    http://www.cphelp.gr
    ------

  3. #3
    Member
    Join Date
    Jul 2007
    Posts
    11

    Default

    Thanks for your reply. However, the cron appears to run just fine. The problem is that when the file is actually executed, I receive an error. It is this error that I do not understand...

  4. #4
    Member
    Join Date
    Nov 2001
    Location
    Athens - Greece
    Posts
    98

    Default

    Your problem is that your system does not know how to run /home/site/cron.php . This file is not a binary file, it needs to be interpreted with php (as other need perl, python, etc) so the system HAS to know how to run it.

    In theory it would be enough to insert a Shebang line in your script, but this would case error from the php interpreter itself.
    ------
    CPanel Tips and Solutions
    http://www.cphelp.gr
    ------

  5. #5
    Member
    Join Date
    Jul 2007
    Posts
    11

    Default

    Thanks a lot! This was indeed the issue, I added the path to php and it all works fine now...

    For whoever battles the same issue: I added

    #! /path/to/php

    before the script and all is fine now.

Similar Threads & Tags
Similar threads

  1. Cron Job, Run PHP script
    By bowers01 in forum New User Questions
    Replies: 2
    Last Post: 11-18-2010, 04:23 PM
  2. Replies: 0
    Last Post: 01-22-2010, 05:53 PM
  3. Running a script immediately (but not a cron job)
    By estado3 in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 07-12-2007, 11:06 PM
  4. Need Help with my Cron Job Script [moved]
    By psquillace in forum Data Protection
    Replies: 5
    Last Post: 08-22-2006, 01:32 PM
  5. Cron job for Mailman script gate_news
    By Ishware in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 09-27-2005, 09:43 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube