Search code examples
bashcronrvmrunner

shell script to execute rails runner via cron with rvm


In crontab I have:

0,30 * * * * sh /path/to/my/script.sh

and in my script.sh I have:

#!/bin/bash
rvm use 1.9.2@r321
cd /path/to/my/proyect
rails runner rails_script.rb

But it doesn't load the rvm in 1.9.2, It stays on the system setting which is 1.8.7 in my case.

What should I do to make sure the runner is running under rvm in 1.9.2 with the gemset r321?


Solution

  • there are at least 4 ways to make cron working with RVM: https://rvm.io/integration/cron/

    personally I prefer the 2. Loading RVM environment files in shell scripts.