Forum Moderators: bakedjake

Message Too Old, No Replies

Problem with PHP called from crontab

can't pass arguments

         

rpking

12:20 pm on Mar 27, 2003 (gmt 0)

10+ Year Member



I've got a PHP script that I'd like to run at scheduled intervals, so I've included it in my cron jobs.

The line looks something like this:

0 0 * * * /path_to_php/php -q /path_to_script/script.php arg1 arg2

The script is being called fine, but the php doesn't seem to be being passed the arguments.

I've tried putting quotes around various parts of the script call, but no luck.

Can anybody shed any light on this one?

rpking

3:18 pm on Mar 27, 2003 (gmt 0)

10+ Year Member



Finally made some progress...

It seems as though the php script is receiving the arguments. However, when the script tries to connect to a mysql database, it is rejected.

When called via a browser, it is accepted. This seems to indicate a user permission error... I assume the cron jobs are running under a different user than the browser php calls...

wruk999

7:44 pm on Mar 27, 2003 (gmt 0)

10+ Year Member



Hi rpking,

The PHP scripts when run through a browser (from the web server) run with very few permissions.

CRON however, is run at root level (most often) and so runs with loads more permissions.

As for the fact that it doesn't connect to the database..I don't really know.

But, just out of interest, when you are connecting to the MySQL server, are you connecting to it as:
'localhost'
'IP Address' or 'hostname'?

Wonder whether this would make any difference?

HTH,
William.

[edit]Typo corrected[/edit]

andreasfriedrich

7:54 pm on Mar 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




>>Wonder whether this would make any difference?

That will depend on your MySQL [mysql.com] permissions [mysql.com].

Andreas

rpking

9:02 am on Mar 28, 2003 (gmt 0)

10+ Year Member



Cheers for that guys... I've come to the conclusion that it is a permissions issue.

Is there anyway to find out what user my cron job is running under? Basically I think that it must be the user that I'm logged in as via SSH. However, I set up permissions on mySQl for that user, and still no success.

I figure that if I can work out through mySQL which user is getting rejected, then I can add that user...

Does that make sense?

andreasfriedrich

12:33 pm on Mar 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The user your PHP [php.net] script runs as has little to do with your MySQL [mysql.com] permissions. The only link is that mysql_connect [php.net] will use that username if none is explicitly specified. But just because a user exists at the OS level does not imply that it exists at the MySQL [mysql.com] level. You would need to add such a user yourself.

Andreas

wruk999

10:11 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



Your CRON tab's will be run as the "root" user.
This is the user you will use to SSH into your server with.

I know it doesn't really help, but if you could make your PHP page into PERL, it can be run from CRONTAB/ROOT very easily, and securely.

I have many perl scripts running on cron, including stats and backup scripts.