简体   繁体   English

如何从运行 cgi 的脚本中杀死 PID

[英]How do I kill a PID from script running cgi

I'm a newbie in linux administration and I'm running a web server with cgi, and in the bellow script, I want to do SIGHUP to x PID, but from the html when I fullfill the PID number and I press on the "STOP BUTTON" that correspond to my first if condition, it doesn't kill the PID.我是ZE206A54E97690CCE50CCCE50C872D70EE896Z管理部门的新手,我正在运行Z2567A5EB7AC9705EB7AC2C98403E0611189DZ与CGI的服务器,并在Bellow脚本中,我想在XPID35555555525255。与我的第一个 if 条件相对应的 STOP BUTTON”,它不会杀死 PID。 Pasting the same line "sudo kill -1 PID" directly in the console, I can kill it.直接在控制台粘贴同一行“sudo kill -1 PID”,我可以杀死它。

> #!/bin/bash

LOG_FILE="/usr/lib/cgi-bin/user.log"
arr=(${QUERY_STRING//[=&]/ })
opcion=${arr[1]}
NombreProceso=${arr[3]}

Fecha=$(date)
echo "-Procesos-" >> user.log
echo "$opcion" >> user.log
echo "$NombreProceso" >> user.log
if [ $opcion = 1 ];
then
    sudo kill -1 $NombreProceso
    echo "$Fecha::Paramos el proceso $NombreProceso" >> user.log
    echo "$opcion" >> user.log
fi
if [ $opcion = 2 ];
then
    sudo kill -19 $NombreProceso
    echo "$Fecha::Pausamos el proceso $NombreProceso" >> user.log
    echo "$opcion" >> user.log
fi

echo Content-Type: text/html
echo -e "
<html>
    <head>
        <title> UOLS WEB Unai Ayoub Jaime</title>
    </head>
    <body>"
echo -e "<textarea style='width:100%;height:90%; resize: none' disabled>"
        ps -aux | less
        echo -e "</textarea>"
echo -e "
    </body>
</html>
"

Finally I got it.最后我得到了它。 The problem was in the file sudoers I excecute it as a root visudo and I put bellow root ALL... www-data ALL=NOPASSWD: /bin/kill so the apache2 user "www-data" can kill any pid for example, if I want to execute a reboot order, I should add to www-data ALL=NOPASSWD: /bin/kill,/sbin/reboot so I can handle with that command.问题出在文件 sudoers 中,我将它作为 root visudo 执行,然后将其放在 root ALL... www-data ALL=NOPASSWD: /bin/kill 所以 apache2 用户“www-data”可以杀死任何 pid 例如,如果我想执行重启命令,我应该添加到 www-data ALL=NOPASSWD: /bin/kill,/sbin/reboot 以便我可以处理该命令。 And don't forget to give the script as a owner www-data.并且不要忘记将脚本作为所有者提供 www-data。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM