Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 730
c2h2 Avatar asked Mar 09 '11 05:03

c2h2


People also ask

Who is the singer of Why?

Why? (styled as WHY?) is an American alternative hip hop and indie rock band. The band was founded in 2004 by Cincinnati rapper and singer Yoni Wolf, who had been using Why? as his stage name since 1997.


2 Answers

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.

like image 184
drewrobb Avatar answered Sep 28 '22 06:09

drewrobb


your cron isn't inheriting your environment. try echoing "$PATH" to a file to see what it's set to.

You could also just do "PATH=/usr/bin/ruby && foo.rb"

like image 31
Cliff Avatar answered Sep 28 '22 08:09

Cliff