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

>
> On May 20, 1:11 pm, Frederick Cheung <[email protected]> 
> wrote: 
> > On May 20, 10:12 am, Tushar Gandhi <[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 
>
>
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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to