On Raspberry Pi 3B running on Raspberry Pi OS 64. Trying to make a Python script executed every minute but don't work. To edit crontab, I use :
sudo crontab -e
And put this line in file :
*/1 * * * * sudo /bin/python3 /home/pi/Documents/script_test01.py`
I also tried : */1 * * * * sudo python3 /home/pi/Documents/script_test01.py
Here my script, simply publish in a MQTT broker (script works by direct call in shell: python3 script_test01.py
):
#!/usr/bin/env python3
import time
import paho.mqtt.client as mqtt
client_mqtt = mqtt.Client("Script-crontab")
client_mqtt.connect("localhost")
client_mqtt.publish("RandomTempValuesSimulator", "Hello !")
client_mqtt.disconnect()
exit()
I did a stop and start cron service with :
sudo systemctl stop cron.service
sudo systemctl start cron.service
Nothing more happened.
CodePudding user response:
Make sure your script is executable. The interpreter is usually at /usr/bin/python3
(not /bin/python3
) but you don't need that since you have the #!
on top of your script.
Why are you editing root
's crontab? Why not just your own? Check your /var/log/syslog
files for any errors in the execution.
CodePudding user response:
Solved.
When i did crontab -l
, i've got no crontab for pi user
.
Problem solved without "sudo" with command crontab -e
and edit the blank crontab file openned and put this command : */1 * * * * /bin/python3 /home/pi/Documents/script_test01.py