Cron job not working

I have created a Yii command that needs to be run every month. If I go to my protected folder and run the command manually:

protected/yiic ganadores

It works fine. I have tried to add the following command line to etc/cron.hourly and etc/crontab with no success:


/usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores


0 0 1 * * root /usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores

If I run the file ganadores inside etc/cron.hourly manually, it’s working also.

What am I missing here?

Your script runs fine without /usr/bin/php5 - so why do you add this when you set up the cron command?

Well, I’m not a linux expert. I read that one problem could be that the shell that runs the scripts didn’t find php5 in its paths and I included it, as it works when running it manually too.

Here are some suggestions which may offer some help in diagnosing this:

  1. Try running the script using its absolute path from a directory other than your protected folder since the cron will likely not run with that as its pwd.

  2. Look in the cron log (/var/cron/log).

  3. Append the following to the cron command:

2>&1 | mail your@email.address


0 0 1 * * root /usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores 2>&1 | mail your@email.address

This will send you an email with anything outputted to the out or error streams by the script.

Finally got it working… I had some extra spaces in the command line. Used tab instead spaces and it started working…