How to run scl enable rh-python36 in Linux crontab

Because scl enable rh-python36 create new virtual environment for Python, within this environment, you can use your installed Python 3.6 but this virtual environment not applied automatically while running in a crontab.

So, in order to use Python 3.6 in Linux crontab, you have to run your python files in activated new virtual environment.

My run.sh file:

#!/bin/bash
now=`date`
echo "[$now]Running script now ..."
scl enable rh-python36 "cd /opt/wdir/ && pipenv run python main.py" >> /var/log/logrun.txt
echo "[$now]All done now" 

and my crontab:

* 7 * * * /opt/wdir/run.sh > /var/log/logrun.txt 

Another way is to set scl at the crontab directly:

* 7 * * *  scl enable rh-python36 "cd /opt/wdir/ && pipenv run python main.py" > /var/log/logrun.txt 

More about Linux crontab here.

Happy working!

Related:  How to setup crontab on Ubuntu 18.04

Leave a Reply

Your email address will not be published. Required fields are marked *