如何使用带有cron的rbenv运行Ruby脚本 [英] How to run a Ruby script using rbenv with cron

查看:67
本文介绍了如何使用带有cron的rbenv运行Ruby脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将rbenv和cron一起运行Ruby脚本。
我知道我需要加载rbenv才能加载正确的Ruby版本。

I'm trying to run a Ruby script using rbenv with cron. I know that I need to load rbenv in order to have the right Ruby version loaded.

我已经尝试过以下选项:

I've tried options like this:

* / 10 * * * * / bin / bash -c'源$ HOME / .bashrc; cd / data / app;红宝石-v’>> /tmp/logfile.txt 2>& 1

*/10 * * * * /bin/bash -c 'source $HOME/.bashrc; cd /data/app; ruby -v' >> /tmp/logfile.txt 2>&1

,但是由于该会话不是交互式的,因此我没有正确的Ruby版本。
我发现了这样的示例:

but as the session is not interactive, I'm not having the right Ruby version. I've found example like this:


15 14 1 * * export BASH_ENV = / path / to / environment&& / full / path / to / bash -c’/full/path/to/rvm_script.rb'

15 14 1 * * export BASH_ENV=/path/to/environment && /full/path/to/bash -c '/full/path/to/rvm_script.rb'

这两个都不起作用。然后我写了一个加载器,它只能在当前shell中加载rbenv,但是不起作用。

It didn't work neither. Then I wrote a loader, which only load rbenv in the current shell but it doesn't work.


* / 1 * * * * / bin / bash -c'$ HOME / .rbenv / loader.sh; cd / data / app /;红宝石-v’>> /tmp/logfile.txt 2>& 1

*/1 * * * * /bin/bash -c '$HOME/.rbenv/loader.sh ; cd /data/app/; ruby -v ' >> /tmp/logfile.txt 2>&1

现在我正在寻找另一种加载方式...有什么想法吗?

Now I'm searching for another way to load it ... any ideas?

推荐答案

我找到了加载rbenv的解决方案。要么使用将rbenv导入到PATH的加载器,要么:

I've found a solution to load rbenv. Either with a loader importing rbenv to the PATH :


* / 1 * * * * / bin / bash -c’。 $ HOME / .rbenv / loader.sh; cd / data / app /; ruby -v'

*/1 * * * * /bin/bash -c '. $HOME/.rbenv/loader.sh ; cd /data/app/; ruby -v'

'$ HOME / .rbenv / loader.sh'之前的'。'很重要,它运行脚本在当前shell中

The '.' before '$HOME/.rbenv/loader.sh' is important, it runs the script in the current shell

或者不使用装载程序,效果更好:

Or without loader, which is better :


* / 1 * * * * / bin / bash -c'export PATH = $ HOME / .rbenv / bin:$ PATH; eval $(rbenv init-); cd / data / app /; ruby -v’

*/1 * * * * /bin/bash -c 'export PATH="$HOME/.rbenv/bin:$PATH" ; eval "$(rbenv init -)"; cd /data/app/; ruby -v'

这篇关于如何使用带有cron的rbenv运行Ruby脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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