Skip to content Skip to sidebar Skip to footer

Referencing Ini File Fails In Cron

I have a python script that queries a database. I run it from the terminal with python3 myscript.py I've added a cron task for it in my crontab file */30 9-17 * * 1-5 python3 /path

Solution 1:

Instead of running "python3 myscript.py" in the directory where it is present, try running it from some other directory (like home directory). Most likely you will see the same issue.

Note that cron's current-working-directory is different on different systems. So, the safest method is to explicitly switch to the directory where your script is and run the command there:

cd /path/to/my/python/script\ directory\ space/ && python3 myscript.py

Solution 2:

Try this:

import os

...

change --> filename=database.ini

for --------> filename=os.path.dirname(__file__)+'/database.ini'

Post a Comment for "Referencing Ini File Fails In Cron"