问题
I am using raspberry pi 3(raspbian jessie) to capture image using fswebcam remotely using shell script and php. Since "motion" is running i need to stop the service then capture image and then restart it.
#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
sudo service motion stop
fswebcam -r 640x480 --no-banner /var/www/html/sm/webcam/$DATE.jpg
sudo service motion start
The script works fine in terminal.Script is saved in var/www/html/sm. chmod +x webcam.sh also checked.
I also wrote a php script to execute above script using apache2 server.
<?php
$output = shell_exec('/var/www/html/sm/webcam.sh');
echo "<pre>$output</pre>";
?>
I was looking for a solution for past 6 hours. No luck. Tried to add www-data ALL = NOPASSWD: /var/www/html/sm/camera.php, www-data ALL = NOPASSWD: /var/www/html/sm/webcam.sh in /etc/sudoers. Changed permissions for folders www,html,sm. changed sudo with visudo. nothing worked. Php files does nothing, Please help me.
来源:https://stackoverflow.com/questions/42473246/how-to-run-sh-script-with-php