通过apache Web服务器通过php脚本运行sh脚本
我编写了一个脚本,用于在磁盘连接到具有特定UUID的卷时装载磁盘通过apache Web服务器通过php脚本运行sh脚本,php,apache,raspberry-pi,sh,Php,Apache,Raspberry Pi,Sh,我编写了一个脚本,用于在磁盘连接到具有特定UUID的卷时装载磁盘 #!/bin/bash #run script and store in PATH the path to disks pathD=$(python /home/pi/scripts/AUTOMOUNT/disco1.py 2>&1) #echo $pathD ###print disk's path #mount it in PATH if [ $pathD ==
#!/bin/bash
#run script and store in PATH the path to disks
pathD=$(python /home/pi/scripts/AUTOMOUNT/disco1.py 2>&1)
#echo $pathD ###print disk's path
#mount it in PATH
if [ $pathD == 'None' ] ###Stop script if disk not present###
then
echo 'Disk not present'
exit
fi
sudo mount $pathD /media/Drive1
echo 'Disco 1 montato'
为了在没有sudo的情况下运行这个程序,我修改了sudoers文件,其中添加了行
pi ALL= NOPASSWD: /home/pi/scripts/AUTOMOUNT/monta1.sh
脚本在shell中运行良好
现在我需要在一个PHP脚本中运行它,该脚本是从ApacheWebServer主页触发的。剧本是
<html>
<body>
<?php
$delay = 10;
if($_POST['button1'] == 'ON')
{
//action for ON
$output1 = shell_exec('sh /home/pi/scripts/PINS/disk1ON.sh');
echo $output1;
$output2 = shell_exec('sh /home/pi/scripts/AUTOMOUNT/monta1.sh')
echo $output2;
}
else if ($_POST['button1'] == 'OFF')
{
//action for OFF
$output = shell_exec('sh /home/pi/scripts/PINS/disk1OFF.sh');
echo $output;
}
?>
</body>
</html>
但什么也没发生
如何使其工作?改用,以便捕获输出和退出代码。没有退出代码,您只是在黑暗中调试。我尝试了:exec(sh/home/pi/scripts/PINS/disk1ON.sh',$output,$exit_-code);echo$输出;echo$exit_代码;但页面仍然是空的。。。
wwwuser ALL=NOPASSWD: /home/pi/scripts/AUTOMOUNT/monta1.sh