From: Arun Tomar Date: 2012-06-03T04:35:15+09:00 Subject: Re: rvm - how to run a ruby script via crontab? This is a multi-part message in MIME format. --------------090409080400030403070305 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 06/03/2012 12:57 AM, Wybo Dekker wrote: > I have, for the first time, installed ruby using rvm. > I run my backups via crontab, calling a bash script that runs a ruby > script. However, that script now tell me that it doesn't know about ruby. > So I entered two lines in the bash script: > > RVM=/usr/local/rvm/scripts/rvm > test -e $RVM&& source $RVM > > and it runs OK; but it seems to me that this is not the way it should be > done. Is it? > Cron runs as sh shell. it doesn't read bashrc or profile.d files like rvm.sh. so it will not know where to find ruby that's installed in rvm. for one of our project this is how we've been running things: Note : We recommend to add cron job for checking the available network connections. Add following into the crontab : */5 * * * * bash -c 'source /etc/profile.d/rvm.sh&& /usr/bin/env ruby /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ispunity monitor' also have a look at this https://rvm.io/integration/cron/ -- Regards, Arun. --------------090409080400030403070305 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit On 06/03/2012 12:57 AM, Wybo Dekker wrote:
I have, for the first time, installed ruby using rvm.
I run my backups via crontab, calling a bash script that runs a ruby
script. However, that script now tell me that it doesn't know about ruby.
So I entered two lines in the bash script:

  RVM=/usr/local/rvm/scripts/rvm
  test -e $RVM && source $RVM

and it runs OK; but it seems to me that this is not the way it should be
done. Is it?


Cron runs as sh shell. it doesn't read bashrc or profile.d files like rvm.sh. so it will not know where to find ruby that's installed in rvm.

for one of our project this is how we've been running things:

Note : We recommend to add cron job for checking the available network connections. Add following into the crontab : 
    */5 * * * * bash -c 'source /etc/profile.d/rvm.sh && /usr/bin/env ruby /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ispunity monitor'

also have a look at this

https://rvm.io/integration/cron/

-- 
Regards,
Arun.
--------------090409080400030403070305--