Load login shell inside user cronjob
- by sa125
I'm trying to run a rake task using a scheduled cronjob. My crontab looks something like this:
0 1 * * 1-7 /bin/bash -l -c "cd ~/jobs/rake && rake reports:create >> ~/jobs/logs/cron.log"
Ruby on my account is provided by RVM, which is loaded via ~/.bashrc (before the no-interaction check):
# load RVM env
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# ... rest of logic
Time and again, this task fails to run since RVM isn't loaded when the task is called (uses system's /usr/bin/ruby instead), and gem dependencies are missing.
How can I make crontab load my shell environment before executing my scheduled jobs? thanks.