How to specify rubygems path in environment without Ruby script?

I wrote a script data collection for Cacti in Ruby and it works fine from the command line, but Cacti runs the script through "env -i", which breaks the environment, so Ruby cannot find the rubygems library ("in` require": no such file for download - rubygems (LoadError) "). How can I get around this?

+3
source share
3 answers
#!/bin/sh

#export LOAD_PATH=whatever 
#export RUBYLIB=whatever
#export RUBYOPT=whatever
#export RUBYPATH=whatever
#export RUBYSHELL=whatever
#export PATH=$PATH:whatever
exec ruby -x. $0 "$@"

#!/usr/bin/ruby
require 'rubygems'
require 'open4' # or whatever

# rest of ruby script here

script, ruby ​​ -x, , #!.*ruby. . . -x noop, . . Ruby script.

, , , - , , , Ruby. , , Ruby, ...

+3

, $LOAD_PATH ( , ). , , :

ENV['GEM_HOME']
ENV['GEM_PATH']

:

require 'rubygems'
puts Gem.path

: comp.lang.ruby

+2

Can you change any of the following values ​​in a Ruby script: $ :, $ -I or $ LOAD_PATH? All of this simply points to the same array that indicates where Ruby is looking for classes and other ephemerals ...

>> $LOAD_PATH
=> ["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-darwin9.5.0", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-darwin9.5.0", "."]
0
source

Source: https://habr.com/ru/post/1719755/


All Articles