【发布时间】:2022-01-11 00:49:29
【问题描述】:
我在 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 对我不起眼的项目有什么影响?
【问题讨论】: