Gem在RVM env中的Ruby cron作业中找不到 [英] Gem not found in Ruby cron job in RVM env

查看:145
本文介绍了Gem在RVM env中的Ruby cron作业中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图在我的旧PPC机器上运行一个简单的ruby脚本,在RVM环境中运行10.5。回答此帖子。 / p>

这是cron中的一行:

  SHELL = / bin / bash 
00 * * * * BASH_ENV =〜/ .bash_profile&& / bin / bash -c'〜/ deggy / onlineGW.rb'

此命令在Bash



这是我的脚本的显着部分:

 

code>#!/ usr / bin / env ruby​​
require'open-uri'
require'nokogiri'
...

以下是cron错误的输出:

  X-Cron-Env:< SHELL = / bin / bash> 
X-Cron-Env:< PATH = / usr / bin:/ bin>
X-Cron-Env:< LOGNAME = sam>
X-Cron-Env:< USER = sam>
X-Cron-Env:< HOME = / Users / sam>
Date:Mon,6 Jan 2014 03:15:00 -0600(CST)
/Users/sam/deggy/onlineGW.rb:3:in`require':没有这样的文件加载 - nokogiri(LoadError)


$ b $ p

确定,因为我运行RVM我已经将我的默认ruby设置为1.9。 3和如上所述,该命令在终端中执行,但不在cron中执行。在游戏中还有其他环境吗?



很明显,有些东西我可以忽略。帮助我看到它,sam

解决方案

我配置了几个不同的操作系统来使用几个CRON风格和RVM。



我第一次尝试 RVM的官方解决方案问题,但没有在FreeBSD和Gentoo下工作。我不得不手动添加所有相关的路径,如下所示,但首先键入 crontab -e 以启动crontab编辑器[1]:

 #atmat的crontab配置
SHELL = / bin / bash
PATH = / home / atma / .rvm / gems / ruby​​-1.9.3 -p0 / bin:/home/atma/.rvm/gems/ruby-1.9.3-p0@global/bin:/home/atma/.rvm/rubies/ruby.1.9.3-p0/bin:/ home / atma / .rvm / bin:/ usr / local / bin:/ usr / bin:/ bin:/ opt / bin:/usr/i486-pc-linux-gnu/gcc-bin/4.5.3
RUBYLIB = / home / atma / .rvm / rubies / ruby​​-1.9.3-p0 / lib / ruby​​ / 1.9.1
GEM_HOME ='/ home / atma / .rvm / gems / ruby​​-1.9.3-p0 '
GEM_PATH ='/ home / atma / .rvm / gems / ruby​​-1.9.3-p0:/home/atma/.rvm/gems/ruby-1.9.3-p0@global'
RUBYOPT = ruby​​gems

%nightly,mail(no)* 8-9 /home/atma/.rvm/rubies/ruby-1.9.3-p0/bin/ruby / usr / local / bin /上面的例子是在Gentoo GNU / Linux下工作的,使用 http://fcron.free.fr/rel =nofollow> fcron 一个更灵活,美观和强大的解决方案,标准cron,但会与任何cron一起工作。



[1]此命令将使用默认系统编辑器打开 crontab


I'm trying to run a simple ruby script on my old PPC machine running 10.5 in an RVM environment.

Searching on SO, I've followed the chosen answer from this post.

This is the line in cron as a result:

SHELL=/bin/bash
00 * * * * BASH_ENV=~/.bash_profile && /bin/bash -c '~/deggy/onlineGW.rb'

This command runs fine in Bash at the root of the user sam.

Here's the salient part of my script:

 #!/usr/bin/env ruby
 require 'open-uri'
 require 'nokogiri'
 ...

Here's the output of the error from cron:

 X-Cron-Env: <SHELL=/bin/bash>
 X-Cron-Env: <PATH=/usr/bin:/bin>
 X-Cron-Env: <LOGNAME=sam>
 X-Cron-Env: <USER=sam>
 X-Cron-Env: <HOME=/Users/sam>
 Date: Mon,  6 Jan 2014 03:15:00 -0600 (CST)
 /Users/sam/deggy/onlineGW.rb:3:in `require': no such file to load -- nokogiri (LoadError)

OK, since I'm running RVM I have set my default ruby to 1.9.3 and as I mentioned above, the command executes in Terminal but not in cron. Is there another environment in play?

So clearly, there's something I'm overlooking. Help me to see it, sam

解决方案

I configured several different operating systems to work with a couple of CRON flavors and RVM.

I first tried RVM's official solution to the problem but didn't work under FreeBSD and Gentoo. I had to manually add all relevant paths as showed bellow but first type crontab -e in order to launch the crontab editor[1]:

# atmat's crontab configuration
SHELL=/bin/bash
PATH=/home/atma/.rvm/gems/ruby-1.9.3-p0/bin:/home/atma/.rvm/gems/ruby-1.9.3-p0@global/bin:/home/atma/.rvm/rubies/ruby-1.9.3-p0/bin:/home/atma/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i486-pc-linux-gnu/gcc-bin/4.5.3
RUBYLIB=/home/atma/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1
GEM_HOME='/home/atma/.rvm/gems/ruby-1.9.3-p0'
GEM_PATH='/home/atma/.rvm/gems/ruby-1.9.3-p0:/home/atma/.rvm/gems/ruby-1.9.3-p0@global'
RUBYOPT=rubygems

%nightly,mail(no) * 8-9 /home/atma/.rvm/rubies/ruby-1.9.3-p0/bin/ruby  /usr/local/bin/morula -s username update

The above example is working under Gentoo GNU/Linux using fcron a more flexible, beautiful and powerful solution to standard cron, but will work with any cron.

[1] This command will open crontab with your default system editor.

这篇关于Gem在RVM env中的Ruby cron作业中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆