我正在尝试运行bash脚本来从BMP280传感器获取值。
#!/bin/bash
echo "Content-type: text/html"
echo ""
read_bme280 --i2c-address 0x76
网页是空白的,在error.log中我得到:
[Tue Mar 29 07:20:40.579423 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: Traceback (most recent call last):
[Tue Mar 29 07:20:40.580102 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: File "/usr/local/bin/read_bme280", line 9, in <module>
[Tue Mar 29 07:20:40.580589 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215:
[Tue Mar 29 07:20:40.581016 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: load_entry_point('bme280==0.2', 'console_scripts', 'read_bme280')()
[Tue Mar 29 07:20:40.581669 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: File "/usr/local/lib/python2.7/dist-packages/bme280/bme280.py", line 210, in main
[Tue Mar 29 07:20:40.582426 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215:
[Tue Mar 29 07:20:40.582811 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: bme280_i2c.set_default_bus(int(args.i2c_bus))
[Tue Mar 29 07:20:40.583487 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: File "/usr/local/lib/python2.7/dist-packages/bme280/bme280_i2c.py", line 22, in set_default_bus
[Tue Mar 29 07:20:40.583991 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215:
[Tue Mar 29 07:20:40.584345 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: default_bus = smbus.SMBus(bus_number)
[Tue Mar 29 07:20:40.584836 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: IOError
[Tue Mar 29 07:20:40.587657 2016] [cgi:error] [pid 1280] [client 10.20.30.127:34334] AH01215: : [Errno 13] Permission denied
从cli开始,脚本运行得很好。 无法弄清楚“权限被拒绝”的问题在哪里。
答案 0 :(得分:0)
如果tte文件归root所有,那么请尝试chmod +s /usr/local/bin/read_bme280
。它应该允许脚本以root权限运行,因此可以访问所有内容。
作为安全预防措施,您可以确保其他用户无法编辑此文件。
答案 1 :(得分:0)
我是用php做的:
<?php
$url1=$_SERVER['REQUEST_URI'];
header("Refresh: 10; URL=$url1");
$output = shell_exec('read_bme280 --i2c-address 0x76');
$parts = explode("\n", $output);
echo "<pre>";
echo "<h2>Temp: " . $parts[2] . "</h2><br />";
echo "<h2>Humidity: " . $parts[1] . "</h2><br />";
echo "<h2>Pressure: " . $parts[0] . "</h2>";