bundle exec not working with crontab

我只是一个虾纸丫 提交于 2019-11-30 19:04:49

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'

The -l option will invoke a full login shell, thus reading your bashrc file and any path / rvm setting it performs.

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.

The user used by cron does not have the correct environment. You can tell cron which user to use. For a bash script, you can so something like:

#!/bin/bash --login
source /home/user/.bashrc
rvm use 2.0.0@gemset #if you use rvm
cd /path/to/project && bundle exec xyz
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!