本文介绍了如何使用带有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

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

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

这两个都不起作用。然后我写了一个加载器,它只能在当前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.

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

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 :

'$ 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 :

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

07-29 19:05
查看更多