From: Dwayne Henderson Date: 2012-06-03T06:14:16+09:00 Subject: Re: rvm - how to run a ruby script via crontab? --001636b2bd1e6c827d04c183c87b Content-Type: text/plain; charset=ISO-8859-1 P.S. This is for a script that runs 24/7 capturing a live stream though, might not exactly suit your needs. On Sat, Jun 2, 2012 at 11:10 PM, Dwayne Henderson < its.code.in.here@gmail.com> wrote: > Hey! > > Just been trying to figure out the same thing. This is what I came up with: > > */10 * * * * lockf -t 0 /home/anonymous/.myscript.rb.lock > /usr/local/bin/screen -d -m -S myscript > /home/anonymous/.rvm/rubies/ruby-1.9.3-p0/bin/ruby > /home/anonymous/myscript.rb > > Uses lockf to make sure the script isn't already running. > > --Dwayne > > On Sat, Jun 2, 2012 at 10:03 PM, Florian Gilcher wrote: > >> >> On Jun 2, 2012, at 9:35 PM, Arun Tomar wrote: >> >> 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/ >> >> >> Newer RVMs also have a script called `rvm_shell`. >> >> $RVM_INSTALL_LOCATION/bin/rvm_shell 1.9.3 -c 'ispunity monitor' >> >> (or similar) should work. >> >> If you have a system level RVM, it should be rather easy. >> >> Regards, >> Florian >> > > --001636b2bd1e6c827d04c183c87b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable P.S. This is for a script that runs 24/7 capturing a live stream though, mi= ght not exactly suit your needs.

On Sat, = Jun 2, 2012 at 11:10 PM, Dwayne Henderson <its.code.in.here@gmail= .com> wrote:
Hey!

Just been tryi= ng to figure out the same thing. This is what I came up with:

*/10 *= * * * lockf -t 0 /home/anonymous/.myscript.rb.lock /usr/local/bin/screen -= d -m -S myscript /home/anonymous/.rvm/rubies/ruby-1.9.3-p0/bin/ruby /home/a= nonymous/myscript.rb

Uses lockf to make sure the script isn't already running.

--= Dwayne

On Sat, Ju= n 2, 2012 at 10:03 PM, Florian Gilcher <flo@andersground.net> wrote:

On Jun 2, 2012, at 9:35 PM, Ar= un Tomar wrote:

=20 =20 =20
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 rub=
y.
So I entered two lines in the bash script:

  RVM=3D/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 installe= d in rvm.

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

=20
Note : We recommend to add cron job for checking the available network conn=
ections. Add following into the crontab :=20
    */5 * * * * bash -c 'source /etc/profile.d/rvm.sh && /usr/b=
in/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/

Newer RVMs also have a script called `rvm_shell`.

=A0 $RVM_INSTALL_LOCATION/bin/rvm_shell 1.9.3 -c 'ispuni= ty monitor'

(or similar) should work.

If you have a system level RVM, it should be rather easy.<= /div>

Regards,
Florian


--001636b2bd1e6c827d04c183c87b--