从Apache的Python脚本关闭计算机

编程入门 行业动态 更新时间:2024-10-24 16:24:23
本文介绍了从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脚本关闭计算机

本文发布于:2023-11-02 13:50:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   关闭计算机   Apache   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!