我在Pi3上有一个python脚本,它将传感器读数发送到mysql数据库,我想在启动时运行该数据库。我在crontab中尝试了几种@boot组合,但数据库表从未获得任何新数据。
脚本的第一行是…
#!/usr/bin/python
脚本运行时使用:
./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 &
(为了简单起见,我将脚本从Pimoroni目录中移走了。(
当从终端运行时,脚本运行良好:
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显示它运行正常(除非脚本名称文本的红色表示不好?(
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
crontab@boot对我卑微的项目有什么不利之处?
尝试python的完整路径并编写日志进行调查:
@reboot /usr/bin/python /home/pi/distance2.py > /home/pi/distance2_cronjoblog 2>&1