仅使用cron:/ usr / bin / env:ruby_executable_hooks:没有这样的文件或目录
我有一个perl脚本,它使用system()来调用shell命令,该命令使用ruby_executable_hooks。
当我从命令行运行此脚本时,它执行完美。
但是当它从一个cron作业运行时,我得到两个错误之一:A)如果我没有chdir()即。 工作目录是/ home / foobar
/usr/bin/env: ruby_executable_hooks: No such file or directory
B)如果我是chdir(“[doc root] / cgi-bin”)
/usr/lib/ruby/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem twurl (>= 0) (Gem::LoadError) from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:214:in `activate' from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:1082:in `gem' from /home/foobar/.rvm/gems/ruby-1.9.3-p551/bin/twurl:22 from /home/foobar/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/gems/1.9.1/bin/ruby_executable_hooks:15
从cron运行时它无法找到某些文件的原因是什么?
我在这里找到答案: https : //unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables
具体来说,我只是把“。$ HOME / .profile;” 在cron命令面前如此:
0 5 * * *。 $ HOME / .profile文件; /路径/到/命令/到/运行
谢谢大家让我走上正轨。
这几乎肯定是您的环境变量的问题。 当从cron运行某些东西时,你的.bashrc
没有被激活,所以可能设置的环境变量,比如你指向的ruby版本和你的PATH
看起来可能不同。
如何解决这个问题取决于您的环境以及您可能使用哪些工具来选择您的ruby版本(rvm,chruby,rbenv等等)。
你可能想要使用类似which ruby
东西来确定要执行什么ruby并在crontab中使用它。