Page 1 of 1

cronjob

Posted: Mon May 17, 2004 1:08 pm
by sirTemplar
hi. i have this php script that i want to run automatically every day at midnight. i edited crontab using vi command crontab -e. now when i crontab -l i see what i did:

0 0 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
,21,22,23,24,,25,26,27,28,29,30,31 * * /fullpath/to/my/phpscript/script.php

now, how do i know that this works? is this enough or do i have to include something on my script? another thing, the file script.php is under a protected directory. thanks.

Posted: Mon May 17, 2004 1:38 pm
by leenoble_uk
You could have saved youself some typing there:
0 0 * * * /path/to/file
would do it every day at midnight.
Whether this works or not all rather depends on if you have the cgi version of php installed.
The regular PHP install is an Apache module and won't run outside of a request from a web browser so you could theoretically write a script to launch your broswer and request this php script but that would be silly.
If you've got the cgi version then I think it should work. I'm not certain as I only have the module version.

Posted: Mon May 17, 2004 3:08 pm
by sirTemplar
:) thx for the reply. i have a cgi version installed. so i will just have to wait tomorrow morning and check if the script work..

Posted: Wed May 19, 2004 2:26 am
by sirTemplar
the cron job is not working at all!

Posted: Wed May 19, 2004 3:11 am
by dave420
If your PHP isn't able to run from the command-line, use a console-based browser (such as lynx) to browse the script page (leenoble_uk - it's actually more common than you think :))

Have you tried using another command in your cron job to test that it's actually doing something? I suggest "touch /some/file/here", then you can see from its timestamp the last time that job ran.

Posted: Wed May 19, 2004 3:13 am
by leenoble_uk
As I said, I don't have the cgi version of PHP so this may not be correct but you might need to make the script an executable.

chmod +x /path/to/cgi-php/script/nameoffile.php

Is there any reason that you can't increase the frequency of the cron in order to see if it's working?

Posted: Wed May 19, 2004 3:16 am
by patrikG
Have a look at these this tutorial and this.

Posted: Wed May 19, 2004 5:54 am
by sirTemplar
i think i figured out something. the path to php is php4. now i have this:

5 * * * * /usr/local/lib/php4 /path/to/script/auto/script.php

this should execute script.php every 5 minutes. when i type

/usr/local/lib/php4 /path/to/script/auto/script.php

on the command line, the script works. but the cronjob doesn't work!!!

any idea?

Posted: Wed May 19, 2004 6:00 am
by leenoble_uk
Did you add the crash-bang or whatever it's called line in the tutorial above?

And that doesn't execute every 5 minutes. That executes at 5 past the hour

/5 * * * * /command

does it every 5 minutes.

Posted: Wed May 19, 2004 6:35 am
by dave420
Change the PHP call to "touch /tmp/touched", and then see if the file /tmp/touched has its timestamp updated. That's a good way to tell if cron is working properly, as it's rare to get problems touching a file you made, especially in the temp directory. If it's working, you know it's something to do with your PHP file, most likely permissions.

dave

Posted: Wed May 19, 2004 8:14 am
by sirTemplar
the cron works perfectly now. thanks for all the help!!! :o

Posted: Wed May 19, 2004 8:27 am
by Pozor
Hello,

what was the final solution, what was the mistake?

greez Pozor