Ad

Crontab (Centos7) With Python Files

- 1 answer

I would like to get help regarding Crontab on Centos 7.

I Need to create the scheduler to run python script (which have 2-5 addition import in the same folder) by using Crontabs

Currently, my crontab looks like this I have

PATH = /srv/git/XXX
30 * * * * cd $PATH/XXX/XXXX  python $PATH/XXX/XXXX/upload.py

I have tried to use a path to the python folder and so on, nothing works. Then I found that the best way is to use .sh files.

WHAT I NEED: Currently, I'm looking to for the best way to run crontab scheduler, for python script(which have an extra import in the same folder) with PROD and DEV variables for future testings. Any better way instead of .sh files? and is .sh is the best way, what if the clean way to write them?

Ad

Answer

I would create a *.sh (e.g. dum.sh) file like this:

#!/bin/bash
export PATH = /srv/git/XXX
python $PATH/XXX/XXXX/upload.py

and in my Crontab file use:

30 * * * * /.../dum.sh
Ad
source: stackoverflow.com
Ad