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?
#!/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
.
-x
, , , - , , , Ruby. , , Ruby, ...
, $LOAD_PATH ( , ). , , :
$LOAD_PATH
ENV['GEM_HOME'] ENV['GEM_PATH']
:
require 'rubygems' puts Gem.path
: comp.lang.ruby
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", "."]
Source: https://habr.com/ru/post/1719755/More articles:Error due to lack of standard fonts (VB.NET) - fontshow to get root node attribute value using linq - c #Managing other windows from a C # application - windowsActiveRecord lock "Failed to compile mapping document: (string)" - c #Можете ли вы дать несколько советов по настройке моей базы данных? - databaseКоманда OPTS в FtpWebRequest/FtpWebResponse - .netSUM Conditional Group in Crystal Reports - crystal-reportsJQuery UI Dialog + jQuery Validate + Tabbing - jquerySqlBulkCopy to a table with a composite primary key - c #Summation by groups and subgroups - crystal-reportsAll Articles