每当作为 cron 执行的 rake 任务中使用错误的 ruby 路径
我正在尝试使用 whenever gem 来执行几个 rake 任务。它似乎正确设置了 cron 任务 - 这里的信息来自生成的邮件输出。以下是执行命令的示例:
/bin/bash -l -c 'cd /path/to/deployed/app && RAILS_ENV=production
rake clean:my:task --silent'
以下是一些环境变量:
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
以下是随后出现的错误:
/bin/bash: /usr/bin/rake: /usr/bin/ruby: bad interpreter: No such file or directory
当我登录时,我可以从相同的环境运行这些 rake 任务目录中,但是当我运行时,
which ruby
我得到
/usr/local/bin/ruby
There does suggest to be a 'rake' in /usr/bin, but running
/usr/bin/rake -T
给了我同样的错误:
-bash: /usr/bin/rake: /usr/bin/ruby: bad interpreter: No such file or directory
解决这个问题的最佳方法是什么?
I am trying to use the whenever gem to execute a couple of rake tasks. It appears to set up the cron tasks correctly - info here is from the mail output that is produced. Here's an example of the command executed:
/bin/bash -l -c 'cd /path/to/deployed/app && RAILS_ENV=production
rake clean:my:task --silent'
And here are some of the environment variables:
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
And here is the error that follows:
/bin/bash: /usr/bin/rake: /usr/bin/ruby: bad interpreter: No such file or directory
When i'm logged in i can run these rake tasks from the same directory, but when i run
which ruby
i get
/usr/local/bin/ruby
There does appear to be a 'rake' in /usr/bin, but running
/usr/bin/rake -T
gives me the same error:
-bash: /usr/bin/rake: /usr/bin/ruby: bad interpreter: No such file or directory
What would be the best way to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
/usr/local/bin/ 在你的路径中吗?当你运行哪个 ruby 时,你得到了 /usr/local/bin/ruby 但当你运行 rake 时,它正在寻找 /usr/bin/ruby
或者你可以像这样符号链接 ruby:
sudo ln -s /usr/local/bin/ruby / usr/bin/.
Is /usr/local/bin/ in your path? When you ran which ruby you got /usr/local/bin/ruby but when you run rake it's looking for /usr/bin/ruby
Or you could just symlink ruby like:
sudo ln -s /usr/local/bin/ruby /usr/bin/.
这是我现在使用的:
由于我只是使用“命令”选项,它允许我在实际的 rake 任务之前执行命令,例如将正确的目录添加到 PATH 以便使用正确的 ruby。
我并不热衷于如何硬编码对 /usr/local/bin 的引用,但是:-/。我不知道如何随时使用“耙子”或“跑步者”选项。但它似乎正在发挥作用。
Here's what i'm using now:
Since i'm just using the 'command' option, it allows me to execute commands prior to the actual rake task, like adding the proper directory to the PATH so that the right ruby is used.
I'm not crazy about how this hard-codes a reference to /usr/local/bin, tho :-/. And i don't know how i could utilize the 'rake' or 'runner' options of whenever. But it seems to be working.
我与 rakes 版本发生冲突...我首先使用 apt-get 安装它,然后使用 gem 安装它...所以我删除了每个版本...我什至必须手动删除 /usr/local/bin/rake 。仅使用 gem 重新安装,现在它可以工作了:)希望它可以帮助别人。
I had a conflict with rakes versions... I had installed it first with apt-get and then with gem... so I removed every version... I even had to remove /usr/local/bin/rake manually. Reinstalled just with gem and now it works :) Hope it helps someone.
在 config/schedule.rb 中添加以下代码行以设置正确的 ruby 路径。
然后运行以下命令
Add bellow line of code in config/schedule.rb to set correct ruby path.
and then run bellow commands