I tried to do the basic operation of trying to automatically execute a python script on a regular basis using cron on Raspberry Pi. Specifically, regular observation of temperature and humidity using the dht11 temperature and humidity sensor. I wrote the program to write to the csv file directly with Thonny.
Check spaces when using cron. Especially before/usr/...
devices: Raspberry Pi3B + sensor; dht11 OS: Rasbian NOOBS_ver_3_5_1 Language: Python 3
I did the following in the terminal:
$ crontab -e
In your favorite editor, write the following at the bottom of the cron file (I use nano) I also asked which python3 and the terminal where the python3 being used is.
$ */1 * * * */usr/bin/python3 /home/pi/hoge/hoge1.py
It's not working, so check the status
$ sudo /etc/init.d/cron status
This is active. And restart cron
$ sudo /etc/init.d/cron restart
Still it doesn't work. Make various settings and see the log
tail -f /var/log/cron.log
Then it works every minute. However, there is no record (not written) in the csv file It's a mystery.
It was a great beginner and a mistake.
$ */1 * * * * /usr/bin/python3 /home/pi/hoge/hoge1.py
What, it didn't seem to work properly when there wasn't one space before/usr. Also, in the place of *, */1 can be done without a space, but in the place of * * * *, one space is put in each. There are many articles on how to use cron, but there weren't many articles about space, so I'll leave it here for your reference.
Recommended Posts