命令在bash上工作,但不在cron上

我使用rails运行docker镜像(使用cron已经安装)。 一切运行良好,除了我想添加一个cron作为一个命令作为,但给我一个错误,当添加到crontab。

以下命令是:

0,2 * * * * /bin/bash -l -c 'cd /app && bin/rails runner -e production '\''Statistic.create_statistic'\'' >> log/cron_log.log 2>> log/cron_error_log.log' 

我每两分钟就运行一次,为了清楚起见,我在这段代码中省略了它。

当我只运行:

 /bin/bash -l -c 'cd /app && bin/rails runner -e production '\''Statistic.create_statistic'\'' >> log/cron_log.log 2>> log/cron_error_log.log' 

有用

我得到的错误是:

  /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- bundler/setup (LoadError) from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /app/config/boot.rb:3:in `<top (required)>' from bin/rails:7:in `require_relative' from bin/rails:7:in `<main>' 

我正在使用每当gem,这似乎是正确的工作。 我究竟做错了什么?

我不熟悉ruby给出一个正确的答案,但它听起来像是你的bash shelllogin中设置的某种环境variables在cron执行期间没有被设置。

你可以在你的cronjob上面设置环境variables

 PATH="/path/to/gems;$PATH" 0,2 * * * * /bin/bash -l -c ' ..... ' 
Interesting Posts