Forum: Ruby on Rails Console script in the crontab

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alex K. (Guest)
on 2007-02-15 23:53
I'm trying to run a console script from my crontab but I'm getting a
console error.  It works fun when I run it from the command line.  I'm
guessing there's an environment variable I need to set but what is it?
Anyone have any advice?

I'm calling it like this:
/Users/alex/links/script/console production < /Users/Alex/links/digg.rb

And getting this error:
/usr/lib/ruby/1.8/irb/completion.rb:10:in `require': No such file to
load -- readline (LoadError)
        from /usr/lib/ruby/1.8/irb/completion.rb:10
        from /usr/lib/ruby/1.8/irb/init.rb:218:in `require'
        from /usr/lib/ruby/1.8/irb/init.rb:218:in `load_modules'
        from /usr/lib/ruby/1.8/irb/init.rb:216:in `each'
        from /usr/lib/ruby/1.8/irb/init.rb:216:in `load_modules'
        from /usr/lib/ruby/1.8/irb/init.rb:21:in `setup'
        from /usr/lib/ruby/1.8/irb.rb:54:in `start'
        from /usr/bin/irb:13
Philip H. (Guest)
on 2007-02-16 00:09
(Received via mailing list)
> I'm trying to run a console script from my crontab but I'm getting a
> console error.  It works fun when I run it from the command line.  I'm
> guessing there's an environment variable I need to set but what is it?
> Anyone have any advice?
>
> I'm calling it like this:
> /Users/alex/links/script/console production < /Users/Alex/links/digg.rb

look into script/runner.  It is meant to do these sorts of things...

So...

say you have RAILS_ROOT/lib/foo.rb:

class Foo
   def self.foobar
     #do your stuff here
   end
end

you could then do:

RAILS_ROOT/script/runner "Foo.foobar" -e production

What's nice is that you can use any of your models class methods as
well...

-philip
This topic is locked and can not be replied to.