How to run .sh script with php?

♀尐吖头ヾ 提交于 2019-12-12 03:46:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!