Calling a PHP script from cron

This is a line from my crontab:

12 12 * * * /home/users/ElburdNDL/www/backups/adddate.php

The permissions of the script is 755 it should execute ok....but it doesn't.

Do I somehow have to give cron the path to PHP or something?

If so, how exactly? Thanks.

Ed

PS Am a total newbie to Linux..

Try instead

12 12 * * * php /home/users/ElburdNDL/www/backups/adddate.php

(or possibly add the path to php before "php")

Giving an executable permission is not enough. An executable script needs a line at the top which indicates the interpreter to use. For Perl, this is like

#!/usr/bin/perl

For php, very likely it's

#!/usr/bin/php

if you would like to invoke the php script without calling php directly. This seems to work on my system with a simple test.

By the way, I think it would have been more coherent if you continue with your previous thread rather than starting a new one.

Many thanks - that did it!

Ed

In the same sense as above, would a perl execution look like

12 12 * * * perl /path/to/script.pl

Or would the #!/usr/bin/perl line of the script suffice?

THanks,
Ed

If you explicitly invoke perl or (or just any interpreter) to execute a script, as in "perl script.pl", script.pl needs not be given executable permission to run at all.

If you would like to directly invoke the script, e.g. "./script.pl", the file needs the top #! line in order to tell which interpreter to use to execute it, and the file needs to have executable permission set.

Thanks.

I've tried both:

12 12 * * * perl /home/users/ElburdNDL/www/cgi-bin/script.pl

and

12 12 * * * /home/users/ElburdNDL/www/cgi-bin/script.pl

(the latter having the #!/usr/bin/perl -w first line)

and neither work :frowning:

What's wrong?

Calling the php script now works fine..!

E

PS As an adition, the script works fine when run through IE..

Ok. You need to learn how to troubleshoot a problem, step by step. Don't jump too far at a time or you'd easily lose track.

First, neglect the cron. Make sure you can run the script on the command line. i.e. run

perl /home/users/ElburdNDL/www/cgi-bin/script.pl

and look at the output. See if that gives what you expect.

If this is not ok, what is the error? To help others diagnose you need to give further details.

Before you are sure the script runs ok, do not put it for use with cron as it is not going to work either.

When run from the command prompt, it says it can't open the file that I'm trying to move in the script.

BUT if i CD to /home/users/ElburdNDL/www/cgi-bin and THEN run the script, it's fine.

The file to be moved is in the cgi-bin.

Ed

Then the script you are referring to seems to be not that well written. A really good script should not really care from which directory it is invoked and still does its job properly.

If the script can't be fixed to function that way, or it's supposed to be only invoked this way, the only way left is to invoke instead by

cd /home/users/ElburdNDL/www/cgi-bin && perl script.pl

If this works on the command line, just paste this onto your cron line.

Working now, many thanks!

E

Is the /home/... in your PATH? If not, add it.