3

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Well when I run $ rvm env --path -- 1.9.2@r321 it returns /home/ubuntu/.rvm/environments/ruby-1.9.2-p290@r321 then I edit my script and add source /home/ubuntu/.rvm/environments/ruby-1.9.2-p290@r321 but when I run the script it says: source: not found, any idea why?
Yes, the file ruby-1.9.2-p290@r321 is located under /home/ubuntu/.rvm/environments/
is it the same machine ? copy-paste that line into your terminal and check if it changes rvm current
Yes it is in the same machine, now if I try tu run the script with sh /path/to/script.sh gives me the error, but if i run this with ./path/to/script.sh works perfectly. what's up with that?
sh is limited shell, run it with bash/zsh
1

I think your problem is: RVM worked only correct in your user shell. Remember after installing rvm you must write somethink like.

'[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

in your .zshrc or .bashrc

Tell cron with wich user you use rvm because rvm must load as a function and with a user that not load rvm as a function it will not worked and the system ruby version is used automatically. Example:

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

alternativly you can install rvm as multiuser show at: enter link description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.