1

Trying to send some output to Slack using cron on an instance of GCP Compute Engine running Linux Ubuntu 18.04.2 LTS.

Output is generated by python script.

Python script is usually run using conda activate my_env and python my_script.py

I have made the bash file executable by doing chmod +x my_script.bash

Here is content of bash file:

#!/bin/bash
source /home/user/miniconda3/bin/activate
conda activate my_env
python /home/user/folder/cron/reports.py -r check_stocks

I would expect adding the following line to crontab -e:

00 21 * * * cd /home/user/folder/cron/ && /bin/bash my_script.bash would give me the same results.

I run cd /home/user/folder/cron/ && /bin/bash my_script.bash in my shell and the script runs fine.

2 Answers 2

1

Make your .py file exacutable too (chmod +x file.py) - otherwise it won't work. You can find similar issue resolved here.

Sign up to request clarification or add additional context in comments.

Comments

0

I had a similar issue and I gave up activating the conda environment and instead called directly the python bin in the miniconda environment folder, like this:

00 21 * * * /home/myuser/miniconda3/envs/my_env/bin/python /home/user/folder/cron/reports.py

I don't think this is the recommended solution, especially if you have a complex project with dependencies and you are importing a lot of modules, but for my simple script it solved the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.