命令来运行一个RUBYJUSTHOSTcron作业 - Command to run a RUBY cron job on JUSTHOST

- 此内容更新于:2016-02-01
主题:

我和Cron的设置是:得到这个错误:当我运行脚本在SSH运行没有问题,但是当我Cron设置它给了我这个错误。我读过很多的解决方案。即使有数位视讯,我尝试过几乎所有。前一个cron使用ruby进行的很顺利,我不知道为什么它不是和我的工作。我忘了说,JustHost帮助他们与其他例子代码:Cron设置

原文:

My Cron Setup is:

0 * * * * ruby /directory/to/ruby/file.rb

And I get this error:

/usr/lib64/ruby/1.9.3/rubygems/custom_require.rb:36:in `require': cannot load such file -- mechanize (LoadError)
from /usr/lib64/ruby/1.9.3/rubygems/custom_require.rb:36:in `require'
from /home4/ofixcom1/rails_apps/products.rb:3:in `<main>'

When I run that script on SSH it runs without a problem, but when I cron setup it gives me this error. I have read a lot of solutions. Even with RVM and I tried them almost all. A previous cron with ruby was running smoothly I dont know why it is not working with mine.

I forgot to mention, on the JustHost help they have this link with examples for other codes: Cron Setup

网友:cron运行时使用相同的用户通过SSH运行它吗?

(原文:Is cron running as the same user that you use when running it via SSH?)

网友:是的,JUSTHOST使用相同的用户比CPANELSSH等等。

(原文:yes it is, JUSTHOST uses the same users for SSH than the CPANEL and so on.)

网友:因为cron不运行在一个交互式/登录会话,我怀疑这不是装载如或者RVM环境配置。你可以尝试去运行(如这个答案)。如果做不到这一点,谷歌的各种组合“cron,”“区”和“打包机”出现大量的结果。

(原文:Since cron doesn't run things in an interactive/login session, I suspect it's not loading e.g. .bashrc or .profile where the RVM environment is configured. You could try running bash -l -c "ruby ..." instead (as in this answer). Failing that, googling various combinations of "cron," "RVM" and "bundler" turns up tons of results.)

网友:嗨,约旦,谢谢你的回复,。概要文件在目录/home4ofixcom1我应该用这个代替bin/bash吗?

(原文:Hi Jordan, thank you for your reply, the .profile files are in directory /home4/ofixcom1 should I use this instead of bin/bash?)

解决方案:
致力于用RVM包装有一个页面。基本上,你可以直接调用包装器,利用rvm的别名包装器负载区环境的shell脚本是由cron调用
原文:

rvm has a page dedicated to using RVM wrappers with cron. Basically, you can

  • call directly the wrappers in $rvm_path/wrappers/<ruby-version>[@gemset-name];
  • use rvm's alias wrappers
  • load rvm environment in a shell script that is being invoked by cron