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)