PDA

View Full Version : Cron job not running



gbanse
08-09-2005, 05:51 AM
Gr.... For the life of me I can't seem to get a cron job to run. The script works fine when I call it from a browser but I can't seem to get it to execute using cron. The cron entry is:

0,10,20,30,40,50 * * * * /var/www/html/new/cron.php > /dev/null

I believe that should run the script every 10 minutes. Right?

gbanse
08-09-2005, 07:28 AM
I finally got it working. Instead of running the PHP file directly the application came with a CuRL script to be run so instead of "cron.php" the cron job was set to run "cron-curl.sh". I also added a "2>&1" just after the file path following logrotate as an example.

I'm not exactly sure what that last part is but it works.

sam
08-11-2005, 06:05 PM
I had a similar problem with a perl script. I believe since it's a cron job, it's like a command executed via the shell. So you might need to pass the script to the php executable.

Try ...

0,10,20,30,40,50 * * * * php /var/www/html/new/cron.php > /dev/null

Jonnyb0y
08-14-2005, 03:24 PM
I finally got it working. Instead of running the PHP file directly the application came with a CuRL script to be run so instead of "cron.php" the cron job was set to run "cron-curl.sh". I also added a "2>&1" just after the file path following logrotate as an example.

I'm not exactly sure what that last part is but it works.

'2>&1' means to take standard error (2> = standard error, > = standard out) and combine it with whereever standard out is going. For example, here is a very simple program in C that writes to both stderr and stdout. I then compile it and run it 4 different ways. First I run it without any redirection, then I redirect things to /dev/null (to supress their output).


[wendel ~/temp]$ cat test.c
#include <stdio.h>

int main () {
fprintf( stdout, "This is going to stdout\n" );
fprintf( stderr, "This is going to stderr\n" );
return 0;
}

[wendel ~/temp]$ cc test.c -o test
[wendel ~/temp]$ ./test
This is going to stdout
This is going to stderr
[wendel ~/temp]$ ./test 2> /dev/null
This is going to stdout
[wendel ~/temp]$ ./test > /dev/null
This is going to stderr
[wendel ~/temp]$ ./test > /dev/null 2>&1
[wendel ~/temp]$


Note that putting 2>&1 at the end is significant. See http://www.unix.org.ua/orelly/unix/upt/ch08_13.htm for information on why :).