Helpful Information
 
 
Category: UNIX Help
running script with crontab

Im trying to execute a php file with cron that will email me every minute(just for testing), but can't for some reason, these are the 2 crontabs i've tried from some examples but they aren't executing. Any ideas, i've never used cron before, but from what i've read it's not much more complicated than what i have

crontab:
* * * * * lynx -dump http://www.abc.com/testcron.php
or
* * * * * /usr/local/www/htdocs/testcron.php

testcron.php:

mail("me@abc.com","test","this is a test");

where you have asterisks you tell cron when to execute the line. pobably any time, any minute, any second is not valid ;)

this is the order and meaning of the 5 values and their range (taken from FreeBSDīs man pages):


minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)


also maybe the path is not set, so you need to supply the full path to lynx.

Additionally, with the second attempt


* * * * * /usr/local/www/htdocs/testcron.php

you need to make certain that testcron.php is executable from the command line. What happens when you run testcron.php from the commandline? If it doesn't work then you need to read documents such as http://www.devarticles.com/art/1/231

* * * * * lynx -dump http://www.abc.com/testcron.php

What you have listed in your first example is correct. You may, however, need to specify the full path to lynx (the cron daemon may not know where 'lynx' is). From the command line, try 'whereis lynx', and use the output in your crontab:
* * * * * /usr/local/bin/lynx -dump http://www.abc.com/testcron.php

And just to make sure that the php page is not the problem, hit your 'testcron' page manually (by using the same command in your teminal window: "/path/to/lynx -dump...") and make sure that you get the mail.

thanks everyone

I've executed both from the command line:
/usr/local/bin/lynx -dump http://www.abc.com/testcron.php
and
lynx -dump http://www.abc.com/testcron.php

and both executed.

but using my crontab:
* * * * * /usr/local/bin/lynx -dump http://www.abc.com/testcron.php
or
1 * * * * /usr/local/bin/lynx -dump http://www.abc.com/testcron.php

neither would execute. I'm stumped

... btw this is off-topic, this is the php forum. this discussion should be moved to the linux forum (iīll ask the mod, wait...).

are you using linux? which distribution?

maybe there is some other problem.
- did you check if cron is running at all? ("ps ax|grep cron")
- did you read the logs? (/var/log/cron or /var/log/messages)

Well, it's half on topic and can be an issue that people run into when trying to schedule a PHP script to run through cron.

So you say that those lines work from the command line, but they don't work in cron, right? What are all of the steps you're doing to add this line to your cron? If I remember correctly, there are a couple steps involved to get this going. Or, like someone else said, is cron even running?

---John Holmes...

Hi John,
I login to my server thru telnet do the following command:
crontab /path/to/my/crontab

then to check it:
crontab -l
this shows me the contents of my crontab

and as far as testing to see if cron was running, I used

- did you check if cron is running at all? ("ps ax|grep cron")
and this was the response:

70850 ?? IsJ 0:47.73 cron
71611 p6 S+J 0:00.00 grep cron

i have no idea if that means yes or no.

this means yes, it is running :)

did you find the log files? (i looked, mine go to /var/log/cron, but maybe i set this up...)

I found and checked the /var/log/cron file and there weren't any entries referring to my crontab. Where would i find errors if there were any trying to run a crontab?

This is pretty much off-topic for the PHP list now, but try add this line to your crontab:

* * * * * date >> /your/home/dir/cron.txt

(replace /your/home/dir/ with the full path to your home directory)
Let it run a couple minutes then check if it created a file called 'cron.txt' that has a bunch of dates in it...

Yes, it is now.

mikeShank, you can find all error messages concerning cron like this:

grep -iR "cron" /var/log

(grep: case insensitive, Recursive)

tail -f /var/log/cron
displays the last ten entries in real time

If you solved your problem please share your solution.
Thank you










privacy (GDPR)