dsuoedtom207012191 2018-03-04 13:44
浏览 86
已采纳

通过php和bash执行服务命令

I want to start a bash script from a html page. This script is supposed to modify a file and reload asterisk service. I'm using PHP to do so.

My php script :

<?php
$field1 = $_GET["P1"];
$field2 = $_GET["P2"];
$field3 = $_GET["P3"];
echo "$field1 $field2 $field3 ";
$output = shell_exec("/var/www/html/script.sh $field1 $field2 $field3");
echo "<pre>$output</pre>";
?>

And my bash script :

#!/bin/bash
num1=$1
num2=$2
num3=$3
for i in 1 2 3
do
    temp="num$i"
    if [ -z  ${!temp} ]
    then
        :
    else
        echo "${!temp}" >> /etc/asterisk/file.conf
    fi
done
sudo service asterisk reload

I tried adding apache to /etc/sudoers, it doesn't work, not even with the ALL ALL=NOPASSWD: ALL rule.

I'm stuck with this issue and can't get it working properly. The script by itself is running properly, only the reload part isn't working.

Can someone tell me what to do ? (I'm running CentOS 6.6 with httpd)

  • 写回答

2条回答 默认 最新

  • dpbv85276 2018-03-05 09:39
    关注

    require tty was set in sudoers file, avoiding the command to be executed by apache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀