我现在有这个shell脚本…
nightly.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
我现在已经添加了一些环境变量到我的crontab每@KL-7
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
似乎cron
无法找到您的bundle
可执行文件。您需要找到它(例如使用which bundle
),然后在crontab中指定它的完整路径,或者在crontab顶部设置PATH
环境变量,如下所示:
PATH=/bin:/usr/bin:/path/to/directory/with/bundle/
这可能有帮助:/bin/bash -c
阅读:http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
这是另一个解决方案:
* * * * * ssh localhost 'your command here...'
这将ssh到相同的主机(它是正常环境的源)并发出命令