Centos – linux crond not working

centoscronpermissionsPHP

I have a cronjob which for creat thumbnails. the folder /var/www/html/work/ has permission 744(I think 744 is more safe than 777)

Crontabs

* * * * * /usr/bin/php /var/www/html/work/images.php

php script

$newstore = dirname(__FILE__) . '/images/.$data->name.'jpg';
$width = (int)($data->width);
$height = (int)($data->height);
$desired_width = round((300*$width)/$height);
$desired_height = 300;
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
imagejpeg($virtual_image,$newstore);

EDIT

In browser part. I have login into the phpmyadmin with root, So when I try localhost/work/images.php, it works well., and works in/usr/bin/php /var/www/html/work/images.phpinPuTTY SSH`.

but the job failed in crond. I have restart cron service crond restart all the thing [OK], then tried /etc/cron.allow, return -bash: /etc/cron.allow: No such file or directory, run /etc/cron.deny, return -bash: /etc/cron.deny: Permission denied.

BTY: vi /var/log/httpd/error_log there have no errors hint.

Where is the problem? crond setting? or folder permission?

Best Answer

Oh, god, stop chmoding basic system binaries. No good will come of it.

If you're able to run your script from the command line as root, but it fails in cron, then the most likely issues are:

1) a permission issue (specifically, a basic permission problem, not something system-wide, which is what you're trying to fix with your chmod statements).

2) a PATH issue.

For #1, have you looked at the ownership and permissions on the /var/www/html/images directory? Will the ownership and permissions on this directory allow the user running the cron to modify files?

Actually, how are you running the cron, in terms of the user? Do you have it in the /etc/cron.d directory? If you have placed the cronjob file in /etc/cron.d, then the format will be slightly different, in that you have to put the user who will execute the cron in between the date/time fields and the command.

For #2, I think this is unlikely, since you're specifying the absolute pathname of the executable (/usr/bin/php) and your script doesn't include any extra libraries.