Page 1 of 1

Cron Job scheduling

Posted: 2010-10-02T07:34:11-07:00
by inferno156
I am trying to automate a process by using a Cron job and ImageMagick to adjust a photo at midnight each night.

I am using a php script with the exec commands for imagemagick and if I run the script in a browser it works perfectly. But if I run it through a cron job imagemagick fails to create the image. And I know the cron job is working because the script also sends me an email.

I suspect it has something to do with relative vs. direct paths to the images, but I can't seem to figure it out.

This code works when the script is run manually.

Code: Select all

exec("/usr/bin/convert ./large/test.png -resize 55% ./small/test.png");
This code doesn't seem to work at all. I just grabbed the path from a php error.

Code: Select all

exec("/usr/bin/convert /var/www/vhosts/<domain>/httpdocs/large/test.png -resize 55% /var/www/vhosts/<domain>/httpdocs/small/test.png");
Thanks in advance for any help.

Re: Cron Job scheduling

Posted: 2010-10-02T11:07:23-07:00
by Bonzo
I have a php cron job that works ok with relative paths - out of interest I just use convert not usr/bin/convert.
If I do get any errors they are reported in the email.

Try using your code like this and see if you get any errors:

Code: Select all

echo "<pre>";
exec("convert ./large/test.png -resize 55% ./small/test.png 2>&1", $array);
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";

Re: Cron Job scheduling

Posted: 2010-10-06T20:32:04-07:00
by xpt
inferno156 wrote:I am trying to automate a process by using a Cron job and ImageMagick to adjust a photo at midnight each night.

I am using a php script with the exec commands for imagemagick . . . .
Since it is only a single "convert" command, would it be better to remove an extra layer by doing it right in shell instead of php? Or you need php to feed in all path, file name things?

Re: Cron Job scheduling

Posted: 2010-10-07T00:50:17-07:00
by Bonzo
If the poster is on a shared hosting he probably will not have access to shell ?

Re: Cron Job scheduling

Posted: 2010-10-07T06:18:08-07:00
by anthony
Maybe not an interactive shell, But if php can exec a command, it can exec a shell script!

Actually the PHP exec is itself a shell script!!!