To use crontab with your Raspberry Pi to automate your programs, follow these steps:
- Write your program and note down its location. We’ll be using a program called py_test.py and save it at /home/pi/Desktop/pyprog
- Now open crontab. You may need to open crontab in root (add sudo before the command!).
crontab -e
- Add a new entry at the very bottom with @reboot to specify that you want to run the command at boot, followed by the command. Here we want to run the python program and save the output in log.txt, so our entry is
@reboot sudo python /home/pi/Desktop/pyprog/pytest.py /home/pi/Desktop/pyprog/log.txt
- Now save the file and exit.
- When you restart the pi, the command will be run and we will get the output log file.Be a bit careful with the permissions and making sure that your program runs properly before you put it on boot: you can waste a lot of time trying to figure out what went wrong!
- Having trouble? Check your bootlog:
grep cron /var/log/syslog
sumber :https://www.dexterindustries.com/howto/auto-run-python-programs-on-the-raspberry-pi/
Tidak ada komentar:
Posting Komentar