我已经编写了一个脚本,用于在连接到具有特定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 == '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
并且脚本可以正常运行。
现在我需要在PHP脚本中运行它,该脚本是从Apache webserver主页触发的。脚本是
<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>
并且在调用$ output2命令之前一直正常工作。调用脚本monta1.sh(写在上面的脚本)没有任何反应......
我试图将行添加到sudoers
wwwuser ALL=NOPASSWD: /home/pi/scripts/AUTOMOUNT/monta1.sh
但没有任何反应
我怎样才能让它发挥作用?