views:

48

answers:

3

When I execute a rake task manually, it works fine but when I put the same command in Cron nothing happens:

cd /path/to/my/rails/app && rake daily_import

The Cron log indicates that the command was issues:

CMD (cd /path/to/my/rails/app && rake daily_import)

The rake task logs error and success messages, but nothing is recorded to the log, nothing is done at all. However if I copy and paste the text of the CMD with the same user Cron is running the command in everything works fine. I'm assuming that running a task in Cron should be the same as typing it in myself, is this not correct?

A: 

Is rake in the PATH of the cron user for running this shell?

Rob Di Marco
You can try having the full path to rake in your task (ie, /usr/bin/rake). Also, you might have to specify the rails environment with RAILS_ENV=production.
elektronaut
It wasn't set, but after adding it I still get the same result. Also tried electronaut's suggestion, same result.
jhamburg
+1  A: 

Look for mail that the cron daemon might have sent to the user under which the cron job is running. If a cron job produces output on stderr or stdout, the cron daemon will email that to the owner of the cron job. If something is going wrong (possibly because of a PATH issue, like Rob suggests above), you might see a helpful error message in an email from the cron daemon.

Mox
A: 

I use the following format to run rake tasks, a little more explicit with the paths

0 * * * * /usr/bin/rake -f /path/to/Rakefile daily_import RAILS_ENV=production

I also like to redirect output to a file so I can check the errors

0 * * * * /usr/bin/rake -f /path/to/Rakefile daily_import RAILS_ENV=production > ~/daily_import.log 2>&1
csexton