3

I have a ruby on rails app and I need to schedule a crontab for a rake task.

*/5 * * * * RAILS_ENV=production /usr/local/bin/rake -f /usr/local/www/mysite-web-production/current/Rakefile my_site:export_products >> /var/log/export_feed.log 3>&1

However, it's not working (it works when I do it manually, but not as a crontab) and it's showing me /usr/bin/env: ruby: No such file or directory. I'm not using RVM. I'm using ruby 1.9.3 and rails 3 on Linux.

2

Wherever ruby is, it's not in the $PATH of cron. Find the actual location of ruby by running type -a. Then add it's path to the $PATH environment variable in your crontab.

Example, if you find type -a shows that the path to ruby is /usr/local/bin/ruby (and judging by your path to rake it likely is), your crontab should look like this:

PATH=$PATH:/usr/local/bin
*/5 * * * * RAILS_ENV=production /usr/local/bin/rake -f /usr/local/www/mysite-web-production/current/Rakefile my_site:export_products >> /var/log/export_feed.log 3>&1

Or possibly:

*/5 * * * * RAILS_ENV=production PATH=$PATH:/usr/local/bin /usr/local/bin/rake -f /usr/local/www/mysite-web-production/current/Rakefile my_site:export_products >> /var/log/export_feed.log 3>&1

Either should work.

  • Thanks! let me try it out. type -a didn't return anything though. – bigpotato Oct 18 '13 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.