开发者

Ruby - No gem to load in cronjob

开发者 https://www.devze.com 2023-04-09 01:59 出处:网络
I use rvm. and ruby 1.9.2 is installed in rvm. I have a script开发者_运维百科 and it runs fine in terminal.

I use rvm. and ruby 1.9.2 is installed in rvm.

I have a script开发者_运维百科 and it runs fine in terminal. I have wrote a cron job for the same script:

27 * * * * su - sayuj -c 'cd /path/to/dir; /home/sayuj/.rvm/rubies/ruby-1.9.2-p136/bin/ruby script.rb >> /var/log/script.log 2>&1'

Then it shows no gem is to load error. I think the cron is not referring to the rvm ruby 1.9.2.

How can I fix this issue?


You need to change cd /path/to/dir; to the real directory. Then, create a file named .rvmrc with this content inside:

rvm use 1.9.2

It'll execute every time you enter the directory, setting to the correct version of ruby.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号