bundle exec不能与crontab一起使用

nis*_*ish 9 rake bundle ruby-on-rails crontab

我正在尝试使用crontab执行以下shell脚本:

#!/bin/sh
cd /mnt/voylla-production/current
bundle exec rake maintenance:last_2_days_orders
bundle exec rake maintenance:send_last_2_days_payment_dropouts
Run Code Online (Sandbox Code Playgroud)

crontab条目是

0 16 * * * /mnt/voylla-production/releases/20131031003111/voylla_scripts/cj_4pm.sh
Run Code Online (Sandbox Code Playgroud)

我在邮件中收到以下错误消息:

/mnt/voylla-staging/current/voylla_scripts/cj_4pm.sh: line 3: bundle: command not found
/mnt/voylla-staging/current/voylla_scripts/cj_4pm.sh: line 4: bundle: command not found
Run Code Online (Sandbox Code Playgroud)

我手动运行命令时没有收到错误.不知道这里发生了什么.请有人指出.

谢谢

kik*_*kik 28

在crontab中正确设置所有环境的一个好方法是使用/bin/bash -l:

0 16 * * * /bin/bash -l -c '/mnt/voylla-production/releases/20131031003111/voylla_scripts/cj_4pm.sh'
Run Code Online (Sandbox Code Playgroud)

-l选项将调用完整的登录shell,从而读取您的bashrc文件及其执行的任何路径/ rvm设置.

如果你想简化你的crontab管理并使用这个技巧 - 以及其他人 - 而不必考虑它们,你可以使用Whenever gem.如果你使用capistrano,它也会很好用,在部署时重新生成crontab.


Bjo*_*sen 7

cron使用的用户没有正确的环境.您可以告诉cron使用哪个用户.对于bash脚本,您可以这样:

#!/bin/bash --login
source /home/user/.bashrc
rvm use 2.0.0@gemset #if you use rvm
cd /path/to/project && bundle exec xyz
Run Code Online (Sandbox Code Playgroud)