【发布时间】:2020-07-09 22:10:37
【问题描述】:
我想通过使用从 cron 脚本调用的 python 脚本来扫描我的 Raspberry 环境中的 ble 设备。 但是当我在 cron 中执行此操作时(我的意思是我添加到 sudo crontab -e),我总是得到一个空列表。
当我以 pi 用户身份登录时 - btmgmt (仅)在 su 权限下可以正常工作:
pi@Pluto:~ $ btmgmt find
Unable to start discovery. status 0x14 (Permission Denied)
pi@Pluto:~ $ sudo btmgmt find
Discovery started
hci0 type 7 discovering on
hci0 dev_found: 77:F8:D7:8A:1E:E5 type LE Random rssi -83 flags 0x0000
...
所以在我的 python 脚本中我写了:
flog.write("P01:\r\n")
out = subprocess.Popen(['sudo', '/usr/bin/btmgmt', 'find'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = out.communicate()
flog.write("stderr: " + str(stderr) + "\r\n")
cDvc = stdout.split('\n')
flog.write("Amount of lines = " + str(len(cDvc)) + "\r\n")
for line in cDvc:
line = line + '\r\n'
if debugflag:
print(line)
flog.write(line)
..
从 shell 提示符运行此脚本可以正常工作.. 在日志文件 (flog) 中我得到:...
P01:
stderr: None
Amount of lines = 40
Discovery started
hci0 type 7 discovering on
hci0 dev_found: 70:D0:FD:74:34:AC type LE Random rssi -59 flags 0x0000
AD flags 0x1a
..
将相同的脚本作为 crontab -e 行运行:没有设备出现,我找不到原因:
...
P01:
stderr: None
Amount of lines = 1
P02:
...
谁能帮帮我?
【问题讨论】:
-
您找到解决方案了吗?我正在尝试从 bash 做类似的事情,如果从 cron 调用 btmgmt,我没有得到任何输出
标签: python cron raspberry-pi bluez