Confusing CRON



I’m new to this whole cron job thing and need a tid-bit of help…

The Wiki has a great deal of information, but perhaps a bit too much for a simple “run this php file every night”…

I have 2 php files in a cron folder in my webspace that I would like to run everyday at midnight.
Simples… I setup my title, email, when it runs and make sure locking is set…
but Command? is that just the path to my php file(s) per line?
What’s the full path mean?

If I have a php script in my folder on > / cron / job1.php
Do I enter the path from my domain onwards?

As always, any help is greatly appreciated :slight_smile:


There are many ways to do this, one would be a cron command something like:

/usr/local/php5/bin/php /home/USER/

Note that you need to specify the full path to the php that you want to use first, followed by a space, followed by the full path to the php script.

My preference however is to to do this, invoking a bash shell script from cron, and then calling the php from that script: (all caps is where I’ve sanitized)

$ crontab -l
# minute (0-59),
# |      hour (0-23),
# |      |       day of the month (1-31),
# |      |       |       month of the year (1-12),
# |      |       |       |       day of the week (0-6 with 0=Sunday).
# |      |       |       |       |       commands
0       0      *       *       *    /home/USER/DOMAIN/DIRECTORY/ >/dev/null 2>&1

Which starts a bash script, from there I can set up anything needed in the shell environment that the php will need, and kill any previous versions that might have hung. Note this version also throws away all cron generated email output.

My actual .sh script for that is:

$ more
# Clean out old copies if any
ps auxw | grep "CRON.php" | grep -v 'grep' | awk '{print $2}' | xargs kill
# and run new instance
/usr/local/php5/bin/php /home/USER/

Note: my script runs much more than once a day, so I prefer to have the cron generated emails turned off, that is invoking with stdout and errout redirected to /dev/null. My actual php script does generate email via php mail() when I need to be alerted.


Put simply for me, if I just drop

into the command box, it should work?
(providing I change USER to my actual username)

I’ve never looked at these before, this is a first for me.




Thanks LakeRat, sorry for the late reply but internet has been spotty for me lately.

I’ll give that a go and post if I have any problems. :slight_smile: