Rvm - how to run a ruby script via crontab?

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?

···

--
Wybo

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/

···

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?

--
Regards,
Arun.

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

···

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

RVM: Ruby Version Manager - Using Cron with RVM

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 <flo@andersground.net>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

RVM: Ruby Version Manager - Using Cron with RVM

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

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

RVM: Ruby Version Manager - Using Cron with RVM

Newer RVMs also have a script called `rvm_shell`.

  $RVM_INSTALL_LOCATION/bin/rvm_shell 1.9.3 -c 'ispunity monitor'

That would better, because calling something containing the 1.9.3-p125
would have to be changed with every change of the ruby version.
However, although I suppose I have the newest rvm (1.14.0), I have no
rvm_shell

···

On 2012-06-02 22:03, Florian Gilcher wrote:

On Jun 2, 2012, at 9:35 PM, Arun Tomar wrote:

On 06/03/2012 12:57 AM, Wybo Dekker wrote:

(or similar) should work.

If you have a system level RVM, it should be rather easy.

Regards,
Florian

--
Wybo

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 <flo@andersground.net>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

RVM: Ruby Version Manager - Using Cron with RVM

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

I am sorry, it is "rvm-shell".

[ skade Florian-Gilchers-MacBook-Pro ~ ] which rvm-shell
/Users/skade/.rvm/bin/rvm-shell
[ skade Florian-Gilchers-MacBook-Pro ~ ] rvm --version

rvm 1.12.1 () by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/\]

Regards,
Florian

···

On Jun 3, 2012, at 10:29 PM, Wybo Dekker wrote:

On 2012-06-02 22:03, 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

RVM: Ruby Version Manager - Using Cron with RVM

Newer RVMs also have a script called `rvm_shell`.

$RVM_INSTALL_LOCATION/bin/rvm_shell 1.9.3 -c 'ispunity monitor'

That would better, because calling something containing the 1.9.3-p125
would have to be changed with every change of the ruby version.
However, although I suppose I have the newest rvm (1.14.0), I have no
rvm_shell

--
Florian Gilcher

smtp: flo@andersground.net
jabber: Skade@jabber.ccc.de
gpg: 533148E2

I'm not sure if I'm doing this correctly - I suppose that in the crontab
this is the command to be executed, every 5 minutes (why not once??):

bash -c "source /etc/profile.d/rvm.sh && /usr/local/rvm/bin/rvm-shell
1.9.3 -c 'ispunity monitor'"

But that gives the following error:

/usr/local/rvm/gems/ruby-1.9.3-p194/gems/ispunity-0.0.4/lib/isp_unity_log.rb:10:in
`<top (required)>': Log level must be in 0..7 (ArgumentError)
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/ispunity-0.0.4/lib/isp_unity.rb:4:in
`<top (required)>'
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/ispunity-0.0.4/bin/ispunity:4:in `<top
(required)>'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ispunity:19:in `load'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ispunity:19:in `<main>'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in
`eval'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in
`<main>'

···

On 2012-06-04 03:43, Florian Gilcher wrote:

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'

That would better, because calling something containing the 1.9.3-p125
would have to be changed with every change of the ruby version.
However, although I suppose I have the newest rvm (1.14.0), I have no
rvm_shell

I am sorry, it is "rvm-shell".

--
Wybo

Hi Wybo,

Thanks for bringing this bug to our notice. We reproduced it on our system using ruby 1.9.3-p194. although the same code & gem works fine on ruby 1.9.3-p125. We logging code has been fixed in the source at github, and will be available in the next release after testing, along with the new features and other bug fixes currently being implemented.

We request you to follow us on twitter @ispunity so that we can keep you updated about the next release, and file bug reports on github : https://github.com/aruntomar/isp_unity

···

On 06/04/2012 05:27 PM, Wybo Dekker wrote:

On 2012-06-04 03:43, Florian Gilcher wrote:

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

RVM: Ruby Version Manager - Using Cron with RVM

Newer RVMs also have a script called `rvm_shell`.

  $RVM_INSTALL_LOCATION/bin/rvm_shell 1.9.3 -c 'ispunity monitor'

That would better, because calling something containing the 1.9.3-p125
would have to be changed with every change of the ruby version.
However, although I suppose I have the newest rvm (1.14.0), I have no
rvm_shell

I am sorry, it is "rvm-shell".

I'm not sure if I'm doing this correctly - I suppose that in the crontab
this is the command to be executed, every 5 minutes (why not once??):

bash -c "source /etc/profile.d/rvm.sh&& /usr/local/rvm/bin/rvm-shell
1.9.3 -c 'ispunity monitor'"

But that gives the following error:

/usr/local/rvm/gems/ruby-1.9.3-p194/gems/ispunity-0.0.4/lib/isp_unity_log.rb:10:in
`<top (required)>': Log level must be in 0..7 (ArgumentError)
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/ispunity-0.0.4/lib/isp_unity.rb:4:in
`<top (required)>'
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/ispunity-0.0.4/bin/ispunity:4:in `<top
(required)>'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ispunity:19:in `load'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ispunity:19:in `<main>'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in
`eval'
  from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in
`<main>'

--
Regards,
Arun.