lundi 1 décembre 2014

Why does rbenv not get added to the path when bash -lc is called from a crontab job?


I'm trying to setup a cron job to back up a rails project using the whenever and backup gems.


I have done a standard install of rbenv on Ubuntu to manage my rubies.


In .bashrc



export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"


and in .profile



# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi


So when I run a crontab like:



16 10 * * 1 /bin/bash -l -c 'backup perform -t production >> ~/cron.log 2>&1'


I assume bash -l -c is getting the right path. However, it's not. When I run 'envinstead of the backup command the path was/binand that's it.SHELLwas also equal to/bin/sh`.


I was able to get the backup command to by setting the SHELL and PATH in the crontab file. Is there a way I can get the cron job to run without setting these variables in the file? I'd like to know why bash wasn't loading the .profile and adding rbenv to the path. That seems like the more elegant and clean solution.



Aucun commentaire:

Enregistrer un commentaire