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

My crontab task record is
“35 * * * * /usr/bin/ruby /root/scripts/auto_send_mail_for_hk.rb”

/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

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.

Ryan D. 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 let me try to set the
ruby environment var

On Wed, Dec 15, 2010 at 10:18 AM, Chih tung Chao [email protected]
wrote:

should have:

require “rubygems”

before requiring your email gem.

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

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

Jesus.

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 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.

I also use this for debugging env issues:

% type newshell
alias newshell=‘env -i $SHELL --norc’

On Dec 15, 2010, at 1:18, Chih tung Chao [email protected] 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