I want to have a cron job execute a python script using an already existing anaconda python environment called my_env. The only thing I can think to do is have the cron job run a script called my_script.bash
which in turn activates the env and then runs the python script.
JavaScript
x
4
1
#!/bin/bash
2
source activate my_env
3
python ~/my_project/main.py
4
Trying to execute this script from the command lines doesn’t work:
JavaScript
1
3
1
$ sh scripts/my_script.bash
2
scripts/my_script.bash: 9: scripts/my_script.bash: source: not found
3
What do I need to do to make sure the proper environment is activated. Its ok to explain it to me like I’m 5.
Advertisement
Answer
Don’t call sh
but bash
. source
is a bash command.
JavaScript
1
3
1
- sh scripts/my_script.bash
2
+ bash scripts/my_script.bash
3
Or just
JavaScript
1
3
1
chmod +x scripts/my_script.bash
2
./scripts/my_script.bash
3
since you added the bash shebang.