Results 1 to 4 of 4
Hi,
I'm trying to run a php script from a cronjob and can't seem to get it working.
When I run the script from the shell command prompt:
# ./myscript.php
...
- 02-17-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 2
run a php script from a cron
Hi,
I'm trying to run a php script from a cronjob and can't seem to get it working.
When I run the script from the shell command prompt:
# ./myscript.php
the scripts works fine
I then inserted a cron job using:
crontab -e
and inserted the following:
3 23 * * * /usr/bin/php /var/pathtoMyscript/myscript.php
and nothing seems to happen.
I left off the -q and have a few echo commands within the script but I don't get an email of the output either.
Any ideas??
Thanks.
- 02-17-2010 #2
i will assume apache is running, perhaps you should invoke your php page using wget. still use cron but try:
If you are wanting output then don't use personal crontabs, use the system's crontab, /etc/crontab. There you can set your mailto and even who to run as. Should give you any output the script generates as well.Code:/usr/bin/wget http://localhost/path/to/mypagename.php
linux user # 503963
- 02-17-2010 #3
You could also try
3 23 * * * /usr/bin/php /var/pathtoMyscript/myscript.php >> /home/usershome/myscript.log
If you want to run the cron job as root then (under Ubuntu) sudo crontab -e wont do the job reliably. This drove me nuts for hours!
Instead try
sudo su -
crontab -eIf we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 02-17-2010 #4Just Joined!
- Join Date
- Feb 2010
- Posts
- 2
Thanks for the input everyone. I got it to work by first having the cron navigate to the directory the php was in:
1 3 * * * cd /pathtoPHPfile/;/usr/bin/php -q -f myscript.php


Reply With Quote