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

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

问题描述

我正在尝试在 RVM 环境中运行 10.5 的旧 PPC 机器上运行一个简单的 ruby​​ 脚本.

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

搜索 SO,我遵循了从这个 发布.

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

这是 cron 中的结果:

This is the line in cron as a result:

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

此命令在用户 sam 的根目录下的 Bash 中运行良好.

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'
 ...

这是 cron 的错误输出:

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)

好的,因为我正在运行 RVM,所以我将默认的 ruby​​ 设置为 1.9.3,正如我上面提到的,该命令在终端中执行,但不在 cron 中执行.是否有其他环境在起作用?

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

推荐答案

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

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

我首先尝试了 RVM 的官方解决方案,但在 FreeBSD 和 Gentoo 下不起作用.我必须手动添加所有相关路径,如下所示,但首先输入 crontab -e 以启动 crontab 编辑器 [1]:

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

上面的例子是在 Gentoo GNU/Linux 下使用 fcron 一个更灵活、美观和强大的解决方案标准 cron,但适用于任何 cron.

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] 此命令将使用您的默认系统编辑器打开 crontab.

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

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

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