从Apache的Python脚本关闭计算机 [英] Shutting down computer from a python script in apache

查看:281
本文介绍了从Apache的Python脚本关闭计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无头树莓派,我希望能有一种简单的方法为我的孩子断电。我试着在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脚本关闭计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆