I am trying to solve a bit a of mystery here... We have created an gem which is called via cron.
The mystery is: This works on machine A
but not on machine B
the environments are identical as far as I can tell.
Both machines are Mac OS X 10.6.
I also understand cron runs things in a minimalistic environment.
crontab:
10 2 * * * /Users/michael/.rvm/gems/ruby-1.9.3-p194/bin/my_gem
The error on machine B
is:
/Users/michael/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find my_gem-toolchain (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
from /Users/michael/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /Users/michael/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems.rb:1231:in `gem'
from /Users/michael/.rvm/gems/ruby-1.9.3-p194/bin/my_gem:22:in `<main>'
Here is the contents of /Users/michael/.rvm/gems/ruby-1.9.3-p194/bin/my_gem
#!/Users/michael/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'my_gem-toolchain' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
end
end
gem 'my_gem-toolchain', version
load Gem.bin_path('my_gem-toolchain', 'my_gem', version)
Line 22 is: gem 'my_gem-toolchain', version
Here is the output of running env
via cron on both machines:
SHELL=/bin/sh
USER=michael
PATH=/usr/bin:/bin
PWD=/Users/michael
SHLVL=1
HOME=/Users/michael
LOGNAME=michael
_=/usr/bin/env
I believe this has to do with the GEM_PATH
not being set. However, on machine A
the GEM_PATH
appears not to be set but everything is working.
I would like to have a better understanding as to the workings of ruby. Apparently I am still missing something.
Why does this work on machine A
but not on machine B
?