Closed Thread
Results 1 to 5 of 5

Thread: Help with Cron Jobs please

  1. #1
    innovationslive32 is offline x10Hosting Member innovationslive32 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    4

    Help with Cron Jobs please

    I am trying to run a php file to update database everynight at midnight using cron jobs. But i just cant get it to work.

    My file is in a scripts folder under my addon domain. I am not able to understand the path to the file or to php. I am so confused.

    What command do i give in the cpanel cron jobs page? Can i simply give the URL of my script as the command (http://www.mydomain.com/scripts/cron.php)

    Also, can you please let me know the server timezone so that i can change the time of the cron job to match local midnight time.

  2. #2
    vv.bbcc19's Avatar
    vv.bbcc19 is offline Community Advocate vv.bbcc19 is just really nice
    Join Date
    Jun 2010
    Location
    India
    Posts
    1,505

    Re: Help with Cron Jobs please

    I think an example will help you.
    Suppose you want to Run 'foo.php' every Sunday, capturing output, the example cronjob would be as follows

    * * * * Sun /usr/local/bin/php $HOME/foo.php >> $HOME/log/foo.txt 2>&1

    Provided foo.php is in your public_html folder.
    If you have it any subfolder whos name is "sub_folder_name" without the quotes,the statement would be like

    * * * * Sun /usr/local/bin/php $HOME/sub_folder_name/foo.php >> $HOME/log/foo.txt 2>&1

    Note: foo.txt is the file where in the net feedback of the cron job is stored
    For example, even if a cronjob for executing foo.php fails, if the servers cron function is working, the server would write its feedback in the foo.txt file
    Any confusion?Revert back.
    Last edited by vv.bbcc19; 06-17-2011 at 09:03 AM.
    BCV | Community Support Representative
    █ x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,635

    Re: Help with Cron Jobs please

    One problem. $HOME resolves to his home directory. Which is /home/cPanelUsername . It does not resolved to the document root of his domain, which is /home/cPanelUsrname/public_html

    So, if the scrip and log files are located in your document root (and therefore can be accessed from the web [maybe good, maybe bad]), the proper command line would be:

    /usr/local/bin/php $HOME/public_html/foo.php >> $HOME/public_html/log/foo.txt 2>&1

    OR

    /usr/local/bin/php /home/cPanelUsername/public_html/foo.php >> /home/cPanelUsername/public_html/log/foo.txt 2>&1

    If you do not want the script or log file to be accessible from the web, place them in /home/cPanelUsername and adjust the paths accordingly. More secure, but makes debugging a bit more difficult.
    Nothing is always absolutely so.

  4. #4
    innovationslive32 is offline x10Hosting Member innovationslive32 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    4

    Smile Re: Help with Cron Jobs please

    Thanks guys, its working and the whole concept is also so much clearer to me now.

    Just one thing more - what time do i set so as to run it at midnight local time. (Say local timezone is +0200 from GMT). Does the Cron Job take GMT time or the server time?

    Thanks a ton.

  5. #5
    Skizzerz's Avatar
    Skizzerz is offline Contributors Skizzerz will become famous soon enough
    Join Date
    Nov 2007
    Location
    Texas
    Posts
    2,153

    Re: Help with Cron Jobs please

    I think it runs as server time, which is CST/CDT (I don't know if it auto-adjusts for DST or not)

Closed Thread

Similar Threads

  1. Cron Jobs
    By johnpleasedwomen77 in forum Free Hosting
    Replies: 0
    Last Post: 04-26-2011, 07:12 AM
  2. Cron Jobs
    By tubeclicks36 in forum Free Hosting
    Replies: 1
    Last Post: 01-31-2011, 02:37 PM
  3. Cron jobs
    By evil-sins22 in forum Free Hosting
    Replies: 5
    Last Post: 01-14-2011, 02:05 PM
  4. Cron Jobs
    By taha116 in forum Programming Help
    Replies: 3
    Last Post: 06-03-2009, 06:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers