why bash -l -c “CMD” makes ruby find my gem?

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?

Answers


The -l parameter executes the command in a login shell, which means that it inherits your path and other settings from your shell profile. The cron job, if run without the login shell, will be run without any path environment variables set (such as those set by RVM), which results in the system being unable to find the referenced gems.


Need Your Help

PostgreSQL regexp_replace with matched expression

postgresql plpgsql

I am using PostgreSQL regexp_replace function to escape square brackets, parentheses and backslash in a string so that I could use that string as a regex pattern itself (there are other manipulations

What is a Calendar Queue?

algorithm language-agnostic data-structures simulation priority-queue

I am working on a building a discrete event simulator. Wikipedia mentioned that there are several general purpose priority queues that are good for use in DES's. Specifically, it mentions that a

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.