5

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
bigpotato
  • 275
  • 1
  • 3
  • 10

1 Answers1

4

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.

bahamat
  • 38,658
  • 4
  • 70
  • 103