I followed this tutorial to log my CPU temperature into a .csv-file and try to run the .py script it at bootup with cron.
The script:
from gpiozero import CPUTemperature
from time import sleep, strftime, time
cpu = CPUTemperature()
with open("/home/user/Desktop/cpu_log.csv", "a") as log:
while True:
temp = cpu.temperature
log.write("{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),str(temp)))
sleep(300)
I did a chmod 757
to the python script. Then added it to crontab -e:
@reboot python3 /home/user/Desktop/log.py
If I execute python3 log.py
from shell when the machine is running, the .csv file is being created and written to perfectly.
However when I reboot my machine, I see the script running with ps -aux | grep log.py
.
And I see the .csv file being created once. However not a single line is written to the file and after I delete it, it is not recreated. There is just an empty csv file on the desktop.