Recommend
If you like my work with RVM, please recommend me *with a comment as to why you recommend me* on
Working With Rails – Thank You!
IRC
I am 'wayneeseguin' in #rvm on irc.freenode.net
If I do not respond right away, leave a message and I'll respond or leave you a memo when I am around.
Sponsors
$ rvm help # Documentation Index

Using RVM with Cron

RVM allows few easy ways to integrate with cron

  1. Direct calling RVM generated wrappers.
  2. Loading RVM environment files in shell scripts.
  3. Direct calling custom RVM wrappers (eg. God).
  4. Loading and using RVM in shell scripts.

Direct calling RVM generated wrappers

For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby. You can find them in `$rvm_path/bin`.

So when the project ruby is 1.9.2-p290@projectX then the following cron entries will work using the proper environment:

1 0  * * * /usr/local/rvm/bin/ruby-1.9.2-p290@projectX /path/to/script.rb
1 15 * * * /usr/local/rvm/bin/rake-ruby-1.9.2-p290@projectX update stats

Loading RVM environment files in shell scripts

For every installed ruby and created gemset RVM creates environment files. You can find them by running:.

rvm env --path -- ruby-version[@gemset-name]

Assuming the the project ruby@gmeset is 1.9.2-p290@projectX then calling:

rvm env --path -- 1.9.2-p290@projectX

will return

/usr/local/rvm/environments/ruby-1.9.2-p290@projectX

Example script

Basic shell script for interacting with rvm installed ruby would look like this:

#!/usr/bin/env bash

# load rvm ruby
source /usr/local/rvm/environments/ruby-1.9.2-p290@projectX

bundle install
ruby /path/to/script.rb
rake do something

RVM Documentation Index