"no such file to load -- rails/commands/runner (LoadError)"

Hi,
I am using ruby 1.9.2 and rails 3 for my application.
I have written a bash script which I want to run in cron.
If I directly run the bash file it runs. If I run it through the cron I
get the following error:-
“/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': no such file to load -- rails/commands/runner (LoadError) from /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’
from runner:10:in <main>' from /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’
from runner:10:in `’”

My runner.rb is as follows:-
#!/usr/bin/env ruby

script/runner for rails 3.0

APP_PATH = File.expand_path(’…/…/config/environment’, FILE)
require ‘rubygems’
require ‘rails/commands/runner’

My Bash file is as follows:-
MYPATH=/usr/local/rvm/rubies/ruby-1.9.2-p180/bin
$MYPATH/ruby runner test.rb -e test

Can anyone tell me what is the wrong with this?

Thanks,
Tushar

On May 20, 10:12am, Tushar G. [email protected] wrote:

Hi,
I am using ruby 1.9.2 and rails 3 for my application.
I have written a bash script which I want to run in cron.
If I directly run the bash file it runs. If I run it through the cron I

Cron starts up with a pretty stripped environment - it’s probably not
seeing your rvm install.

Fred

On May 20, 1:11pm, Frederick C. [email protected]
wrote:

On May 20, 10:12am, Tushar G. [email protected] wrote:

Hi,
I am using ruby 1.9.2 and rails 3 for my application.
I have written a bash script which I want to run in cron.
If I directly run the bash file it runs. If I run it through the cron I

Cron starts up with a pretty stripped environment - it’s probably not
seeing your rvm install.

Just noticed that you are explicitly setting the path to ruby, however
i think rvm also sets up environment variables that tell ruby where
gems are and so on.

Fred

On Friday, May 20, 2011 6:13:16 AM UTC-6, Frederick C. wrote:

As others have pointed out, you need to take RVM into account (see more
below).

My Bash file is as follows:-
MYPATH=/usr/local/rvm/rubies/ruby-1.9.2-p180/bin
$MYPATH/ruby runner test.rb -e test

Can anyone tell me what is the wrong with this?

You ought to be using an RVM “wrapper” (run “rvm help wrapper” for more
information). If you create a wrapper for your specific, RVM-managed
version
of ruby (optionally with a specific gemset) then you can reference the
wrapper script as if IT were your ruby. The upshot is that the wrapper
sets up all the environment variables correctly so that ruby and
rubygems
will work correctly.

Since it looks like you’ve got a system-wide RVM install, you might to
something like the following:

$ rvm wrapper ruby-1.9.2 cron

This would create the following in /usr/local/rvm/bin

cron_erb
cron_gem
cron_irb
cron_rake
cron_rdoc
cron_ri
cron_ruby
cron_testrb

You can then run these directly or reference them in system scripts
(like
cron jobs). When you run these wrapper versions for the various
executables,
the paths will first be set up correctly and it should just work:

MYPATH=/usr/local/rvm/bin
$MYPATH/cron_ruby runner test.rb -e test