简体   繁体   中英

crontab python script query

I have a python script on a Pi3 which sends sensor readings to a mysql database, which I would like to run at boot. I have tried several combinations of @boot within crontab, but the database table never gets any fresh data.

The first line of the script is...

#!/usr/bin/python

and the script runs with:

./distance2.py
@reboot  /home/pi/distance2.py &
#  @reboot cd /pyhome/pi/Pimoroni/VL53L1X/Examples && sudo python distance2.py
# @reboot /home/pi/Pimoroni/VL53L1X/Examples/distance2.py &

(I moved the script from the Pimoroni directory for the sake of simplicity.)

When run from terminal, the script works perfectly:

pi@raspberrypi:~ $ ./distance2.py
distance.py
Display the distance read from the sensor.
Uses the "Short Range" timing budget by default.
Press Ctrl+C to exit.

VL53L1X Start Ranging Address 0x29

VL53L0X_GetDeviceInfo:
Device Name : VL53L1 cut1.1
Device Type : VL53L1
Device ID : 
ProductRevisionMajor : 1
ProductRevisionMinor : 15
Distance: 0mm
(1L, 'record inserted.')
Distance: 60mm
(1L, 'record inserted.')
Distance: 60mm

grep shows it's running OK (Unless the red colour of the script name text means something bad?)

ps aux | grep distance2.py
pi        1530  0.0  0.5   7332  2032 pts/0    S+   16:20   0:00 grep --color=auto distance2.py

What's crontab @boot got against my humble project?

Try full path to the python and write the log for investigation:

@reboot /usr/bin/python /home/pi/distance2.py > /home/pi/distance2_cronjoblog 2>&1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM