views:

368

answers:

4

Having the same problems as this post, except I don't think the solution is the same unfortunately.

I'm getting this error message:

Rails requires RubyGems >= 0.9.4. Please install RubyGems

when I run a script/runner job in Cron, but it works perfectly fine when I run it in a terminal on the same server.

The rails server also runs fine. I only have trouble running script/runner's in cron. It seems to want to have a terminal attached...

+4  A: 

Try which ruby and which gem from your cron job and also from the terminal. Are you accessing different binaries? You didn't mention which OS and which shell, but you may have a different $PATH when running headless.

Abie
Thanks that was it. `which gem` returned nothing when running from cron, so i set the PATH environment variable to the same as was set in the my terminal session and now it works fine. Thanks!
Joel
A: 

You wouldn't happen to be working on OSX? You should be installing a newer ruby rails and gems off macports instead. Google for the instructions...

Calyth
A: 

As indicated by earlier posts, your Cron is using a different gem command source — also try which gem and gem -v. You may have a library set in your .bash_profile (or similar shell configuration or perhaps by other means, setting proper Ruby/Rails environment (i.e., Locomotive or other all-in-one environment).

To update your gem setup:

gem update --system

More information here - http://www.rubygems.org/read/book/1

Naum
+1  A: 

The selected answer is completely correct, but something I'd suggest is to NOT use script/runner. The resources required to load the entire stack of your rails application is pretty intense for something to run regularly.

In my past experience, any cron jobs generally only have to deal with data (as opposed to say, generate static files, etc). In this case, you can very simply just load your models up, and since you've written your models the correct way (fat models), you can easily do your data processing with a few model methods.

Of course, all the above depends completely on your task, so take it with a grain of salt :)

I suppose this was a sort of answer to a problem that may not exist, and wasn't asked here, but just thought I'd throw my two cents in ;)

Keith Hanson