I want to run a crontab which will run my file every hour at 0 minutes. I have the (sudo) crontab set up with a single command as follows:
0 * * * * /usr/bin/python3 /usr/folder/test.py
The crontab is running and as far as I can tell is correct, but my python file is not returning the absolute path when the file is run from another location.
What I need is a way to guarantee the absolute path of this text file when it is accessed from the root so that my crontab can run the file.
I've tried using both Path(filename).resolve(), and os.path.abspath(filename) but neither of them work.
import os
print(os.path.abspath("checklist.txt"))
python3 usr/folder/test.py
When I run the file "test.py" while within the folder, I get the expected output
python3 test.py
/usr/folder/checklist.txt
however when I run the same file from the root and access it via a path I get a different result, making using crontab impossible in this context
python3 usr/folder/test.py
/checklist.txt