bundle exec 不适用于 crontab [英] bundle exec not working with crontab
问题描述
我正在尝试使用 crontab 执行以下 shell 脚本:
I'm trying to execute the following shell script using crontab:
#!/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
crontab 条目是
The crontab entry is
0 16 * * * /mnt/voylla-production/releases/20131031003111/voylla_scripts/cj_4pm.sh
我在邮件中收到以下错误消息:
I'm getting the following error message in the mail:
/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
我手动运行命令时没有收到错误消息.不知道这里发生了什么.有人可以指出.
I dont get the error when I run the commands manually. Not sure what's going on here. Could someone please point out.
谢谢
推荐答案
在 crontab 中正确设置所有环境的一个好技巧是使用 /bin/bash -l
:
A nice trick to get all environment properly set up in crontab is to use /bin/bash -l
:
0 16 * * * /bin/bash -l -c '/mnt/voylla-production/releases/20131031003111/voylla_scripts/cj_4pm.sh'
-l
选项将调用完整的登录 shell,从而读取您的 bashrc 文件及其执行的任何路径/rvm 设置.
The -l
option will invoke a full login shell, thus reading your bashrc file and any path / rvm setting it performs.
如果你想简化你的 crontab 管理并使用这个技巧——以及其他技巧——而不必考虑它们,你可以使用 每当宝石.它也与 capistrano 一起玩得很好,如果你使用它,在部署时重新生成 crontab.
If you want to simplify your crontab management and use this trick - as well as others - without having to think about them, you can use the Whenever gem. It also play very nice with capistrano, if you use it, regenerating crontab on deploy.
这篇关于bundle exec 不适用于 crontab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!