Help with Cron Jobs please

Status
Not open for further replies.

innovationslive32

New Member
Messages
4
Reaction score
0
Points
0
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.
 

vv.bbcc19

Community Advocate
Community Support
Messages
1,524
Reaction score
92
Points
48
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:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
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.
 

innovationslive32

New Member
Messages
4
Reaction score
0
Points
0
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.
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
I think it runs as server time, which is CST/CDT (I don't know if it auto-adjusts for DST or not)
 
Status
Not open for further replies.
Top