permission denied to run cron job

I have a cron job that I want to run at 12:01 every night to update all the records in one filed of a table in a database. Currently I am getting an error when the cron job runs saying permission denied. Here is the exact text of the error (with the path changed):

/bin/sh: /xxxxxxx/homepages/33/xxxxxxx/htdocs/xxxxxxxx.php: Permission denied

This is how I have it set up:
the cron job calls the php file.
I have an require once in the php file to connect to the database
then the php file runs

I suspect that the permission denied error is coming because the user name is the username of the database, not the root user of the shell. Do I need to add a user login to my php file for the shell access? If so, how would I go about doing that?

I know the php file is running correctly because when I run it manually, it does what I want it to do.
ksdeanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HappyCactusCommented:
what is the user and group the cronjob is running for?
Can you try to impersonate this user/group and test the program?
Maybe it is not the program but a directory that is inaccessible (.../homepages/33/... ?)
0
ksdeanAuthor Commented:
Well, I did figure the permission denied problem out. It certainly helps if you have the file permissions set to 777.

Now, however, I am getting syntax errors when it tries to run the files. Here is what I am getting:

xxxxxx/homepages/33/xxxxxxxxx/htdocs/xxxxxxxxx.php: line 1: syntax error near unexpected token `('
xxxxxx/homepages/33/xxxxxxxxx/htdocs/xxxxxxxxx.php: line 1: `<?php require('config.php'); ?>'

I know it is likely ignorance on my part, but can I not just call a php file from a cron and have it execute like regular php would on a browser? Here is my php code:

<?php require('config.php'); ?>
<?php


// update tbl_job date field with current date
$result = mysql_query("UPDATE tbl_job SET date = CURDATE()")
or die(mysql_error());  


$result = mysql_query("SELECT * FROM tbl_job WHERE date = CURDATE()")
or die(mysql_error());  

?>
0
allen-davisCommented:
If you want to run the file directly, you should probably put php in front of the  filename something like this so that you're executing the PHP interpreter and giving it the  PHP file instead of trying to execute the PHP file directly.  The system may be getting confused because the 777 file permissions might be marking php as an  executable file when it may not  be setup that way on your system.  

Try this from the command line and  then from the cron job:

php /xxxxxx/homepages/33/xxxxxxxxx/htdocs/xxxxxxxxx.php

to be safe, though, use the  full file path to the  PHP file.


If the PHP file is already hosted on the web server locally, you could also use curl or wget to execute  the web page from the cron. Something like this:

curl "http://<site name>/xxxxxxxxxxxxx.php"  

where htdocs above would be the root for the site
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ksdeanAuthor Commented:
curl did the trick nicely. Thank you SO much for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.