I’m trying to run the following bash script which runs a Python program after activating a conda environment.
source activate manage_oam_users python ~/path/to/script/send.py source deactivate
30 * * * * source /path/to/script/send.bash
I get the following error from cron, although running
source send.bash works perfectly. I’ve also tried using
bash send.bash which works fine when run manually, but results in the same error when run from cron.
/path/to/script/send.bash: line 2: activate: No such file or directory
deactivate are probably scripts located somewhere an entry in your
$PATH variable points to. Usually, software installed locally for one user adds statements to your
.profile file or
.bashrc that extend your
$PATH variable so that you can use the software’s scripts without using full paths.
While your bash loads
.bashrc automatically, CRON won’t do that. There are at least two solutions for this.
A) Full Paths everywhere
Either you use full paths in the script executed by your CRON job, like this:
source /path/to/activate manage_oam_users python $HOME/path/to/script/send.py source /path/to/deactivate
$HOME instead of
~. You can find out the full paths using
which activate and
which deactivate in your shell.
Alternatively you can source your
.bashrc; you will have to look which file extends your
$PATH variable with the anaconda directories) in your CRON tab:
30 * * * * source $HOME/.profile; source /path/to/script/send.bash
Extra: What does source mean?
source is a Unix command that evaluates the file following the command, as a list of commands, executed in the current context.
A commonly used alias for the
source command is a single dot (
Since the cron does not run from the directory in which anaconda is installed, it is unable to find activate. Also your path seems to be missing the root anaconda directory.
Find the location of the activate command and add it to your PATH .
which activate /Users/username/anaconda/bin/activate
In your bash_profile add
additionally, the directory can be defined to be added automatically
script_dir=$(dirname $0) #file_imports source $script_dir"/functions.sh"