gpt4 book ai didi

ruby - 无法让 Rails rake 任务与 crontab 一起玩

转载 作者:数据小太阳 更新时间:2023-10-29 08:28:44 26 4
gpt4 key购买 nike

我目前有这个 shell 脚本 ...

每晚.sh

#!/bin/bash
rvm 1.9.2
cd /home/appname/capistrano/current
RAILS_ENV=production bundle exec rake nightly >> /home/appname/capistrano/shared/log/nightly.log 2>&1

我在我的 crontab 条目中使用它...crontab -e

42 20 * * * /home/appname/nightly.sh

当它运行时我得到这个错误

/home/appname/nightly.sh: line 4: bundle: command not found

我正在使用 RVM

我现在根据@KL-7 向我的 crontab 添加了一些环境变量

SHELL=/bin/bash
HOME=/home/appname
PATH=/home/appname/local/bin:/home/appname/.rvm/gems/ruby-1.9.2-p290/bin:/home/appname/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/appname/.rvm/rubies/ruby-1.9.2-p290/bin:/home/appname/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

现在我明白了...

/home/appname/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler
[minitest-1.6.0, rake-0.8.7, rdoc-2.5.8] (Gem::LoadError)
from /home/appname/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /home/appname/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
from /home/appname/.rvm/gems/ruby-1.9.2-p290/bin/bundle:18:in `<main>'

最佳答案

这可能是因为它抛出错误而您没有捕获它。尝试以下操作:

01 04 * * * /bin/bash -l -c 'cd /home/appname/capistrano/current && RAILS_ENV=production bundle exec rake nightly' >> /home/appname/capistrano/shared/log/nightly.log 2>&1

关于ruby - 无法让 Rails rake 任务与 crontab 一起玩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8620137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com