Search code examples
rubyruby-on-rails-3cron

why #!/usr/bin/env ruby doesn't work in crontab?


I have install ruby by rvm (system-wide), and worked correctly via normal console and my rails program is behaving correctly with both rails runner and apache2+passenger.

Now in a crontab, I called rails runner foo.bar, it gives up, carefully examine the log i see that:

/usr/bin/env: ruby: No such file or directory

Anyone knows why /usr/bin/env doesnt work in crontab?


Solution

  • If you installed ruby via rvm, ruby probably isn't in /usr/bin. Depending on where rvm is installed:

    bash -c "source /usr/local/lib/rvm" && rails runner foo.bar
    

    You probably added a source */rvm to your bashrc that is the correct rvm loading script.