cronjob
Moderator: General Moderators
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
cronjob
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.
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.
-
leenoble_uk
- Forum Contributor
- Posts: 108
- Joined: Fri May 03, 2002 10:33 am
- Location: Cheshire
- Contact:
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.
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.
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
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.
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.
-
leenoble_uk
- Forum Contributor
- Posts: 108
- Joined: Fri May 03, 2002 10:33 am
- Location: Cheshire
- Contact:
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
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?
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?
-
leenoble_uk
- Forum Contributor
- Posts: 108
- Joined: Fri May 03, 2002 10:33 am
- Location: Cheshire
- Contact:
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
dave
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am