Using RVM with Cron
RVM allows few easy ways to integrate with cron
- Direct calling RVM generated wrappers.
- Loading RVM environment files in shell scripts.
- Direct calling custom RVM wrappers (eg. God).
- 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