I have a python file with this content:
from datetime import datetime
print(datetime.today())
If I run this from terminal with python3 file.py > out.txt
I will get the out.txt
file with todays date.
I want to replicate this with cron and schedule this script to run every minute. So the crontab looks like:
* * * * * /path/to/python3 /path/to/file.py >> path/to/out.txt
Now this works and out.txt
does get created but the file is empty and never contains any date. Why is that?
The duplicate mentioned here does not solve my issue. I have tried this with just a simple echo command scheduled every minute with cron tab and it worked.
Somehow this is a python issue. Python is hiding the output. Or there are some other permission issues.