No such file to load -- rubygems (LoadError)

Hi all

I have use ruby to write a shell script to send email automatic, then i
use "#ruby auto_send_mail_for_hk.rb" command to test it and all is
correct, but i got following error when i set it to crontab tast for
automatic run

Please help me, thanks

/root/scripts/auto_send_mail_for_hk.rb:7:in `require': No such file to
load -- rubygems (LoadError)
        from /root/scripts/auto_send_mail_for_hk.rb:7

···

--
Posted via http://www.ruby-forum.com/.

env | grep RUBY

you're probably activating rubygems via your environment. Your script should have:

require "rubygems"

before requiring your email gem.

···

On Dec 15, 2010, at 00:55 , Chih tung Chao wrote:

Hi all

I have use ruby to write a shell script to send email automatic, then i
use "#ruby auto_send_mail_for_hk.rb" command to test it and all is
correct, but i got following error when i set it to crontab tast for
automatic run

Please help me, thanks

/root/scripts/auto_send_mail_for_hk.rb:7:in `require': No such file to
load -- rubygems (LoadError)
       from /root/scripts/auto_send_mail_for_hk.rb:7

Ryan Davis wrote in post #968509:

···

On Dec 15, 2010, at 00:55 , Chih tung Chao wrote:

/root/scripts/auto_send_mail_for_hk.rb:7:in `require': No such file to
load -- rubygems (LoadError)
       from /root/scripts/auto_send_mail_for_hk.rb:7

env | grep RUBY

you're probably activating rubygems via your environment. Your script
should have:

require "rubygems"

before requiring your email gem.

My script already have require "rubygems", and how to set rubygems
environment in my system ?

--
Posted via http://www.ruby-forum.com/\.

http://docs.rubygems.org/read/chapter/3

Jesus.

···

On Wed, Dec 15, 2010 at 10:18 AM, Chih tung Chao <ops.tong@gmail.com> wrote:

Ryan Davis wrote in post #968509:

On Dec 15, 2010, at 00:55 , Chih tung Chao wrote:

/root/scripts/auto_send_mail_for_hk.rb:7:in `require': No such file to
load -- rubygems (LoadError)
from /root/scripts/auto_send_mail_for_hk.rb:7

env | grep RUBY

you're probably activating rubygems via your environment. Your script
should have:

require "rubygems"

before requiring your email gem.

My script already have require "rubygems", and how to set rubygems
environment in my system ?

Then you're prolly using a different ruby in cron than on cmdline. Use full path to ruby in crontab

···

On Dec 15, 2010, at 1:18, Chih tung Chao <ops.tong@gmail.com> wrote:

My script already have require "rubygems"

It's probably "env-related"

Look at:

http://groups.google.com/group/rubyonrails-talk/msg/128b59ee57473cfb

For debugging, run "env" in a shell and at cron and see the differences.

Abinoam Jr.

···

On Wed, Dec 15, 2010 at 7:51 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

On Dec 15, 2010, at 1:18, Chih tung Chao <ops.tong@gmail.com> wrote:

My script already have require "rubygems"

Then you're prolly using a different ruby in cron than on cmdline. Use full path to ruby in crontab

I also use this for debugging env issues:

% type newshell
alias newshell='env -i $SHELL --norc'

···

On Dec 15, 2010, at 07:01 , Abinoam Jr. wrote:

It's probably "env-related"

Look at:

ruby on rails - rake task via cron problem loading rubygems - Stack Overflow

http://groups.google.com/group/rubyonrails-talk/msg/128b59ee57473cfb

For debugging, run "env" in a shell and at cron and see the differences.