Tuesday, November 2, 2021

[SOLVED] Scheduling a python 3.6 script in using crontab/cron

Issue

I'm just setting up a cron tab/job on my Cent OS developement server.

Within my crontab I have the following. (Ignore the time setting, this was added about 15:32 UTC server time just to get the next scheduled run in).

34 15 * * * cd welcomeclient-0.0.5 && python3.6 main.py

In the command line cd welcomeclient-0.0.5 && python3.6 main.py works fine. welcomeclient-0.0.5 is under root in the droplet, and python3.6 is in /usr/bin.

Any suggestions?


Solution

Try using absolute paths in your crontab command:

34 15 * * * cd /foo/bar/welcomeclient-0.0.5 && /usr/bin/python3.6 main.py

or, assuming the main.py does not also make use of relative paths inside of it :

34 15 * * */usr/bin/python3.6 /foo/bar/welcomeclient-0.0.5/main.py


Answered By - omu_negru