我有一个无头树莓派,我希望能有一种简单的方法为我的孩子断电。我试着在Apache Web服务器下面的脚本:
I have a headless Raspberry Pi which I want to have an easy means for my child to power down. I tried the following script in the apache web server:
import os sss = os.popen('echo password | sudo -S shutdown -hP now') print sss.read()但没有任何反应。
But nothing happens.
然后我尝试:
from subprocess import Popen, PIPE, STDOUT p = Popen('echo password | sudo -S shutdown -hP now', shell=True, stdOUT=PIPE, stderr=STDOUT) print p.stdout.read()此外,没有什么是产出和没有工作似乎已经完成。
Also, nothing was output and no work appears to have been done.
我如何从一个网页做一个关机?
How can I do a shutdown from a web page?
推荐答案有关安全方面的原因Apache用户无法运行须藤命令。
For security reasons Apache user cannot run sudo command.
通常这是一个几乎强制性规则来拯救你免受攻击,但对于覆盆子PI的安装可能不会有这个问题,所以你可以再补充的Apache用户的 sudoers文件(或更好,USO visudo命令编辑该文件)。
Usually this is an almost mandatory rule to save you from attacks but for a Raspberry PI installation you may not have this problem so you can just add Apache user to sudoers (or, better, uso visudo to edit that file).
别的东西吗?是的,你可以简单地添加关机权限Apache用户,请按照本教程。总之,你必须改变的/ etc / sudoers文件与
Something else? Yes you may simply add shutdown permissions to Apache user, follow this tutorial. In short you have to change /etc/sudoers with:
%groupName ALL= NOPASSWD: /sbin/shutdown更多推荐
从Apache的Python脚本关闭计算机
发布评论