In my ruby script,I required the gmail gem:
require 'rubygems'
require 'gmail'
when running in shell,it works ok:
ruby my-script.rb
while when I put it in a cron job,it failed to execuate:
* * * * * cd /to/script/directory;/usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/ruby ./my-script.rb
the log shows that the gmail gem can not be loaded:
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- gmail (LoadError)
well, when i do this(put the cmd in bash -l -c 'CMD'):
* * * * * /bin/bash -l -c 'cd /to/script/directory;/usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/ruby ./my-script.rb'
it works ok again.
why?
ps.I know the arg -l
make the bash a login shell,but does that make any difference?