Search code examples
pythoncronraspberry-pi3

Why my crontab request dont work to call a python script


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.


Solution

  • 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