-1

This PHP code should start a shell script at the time saved in the $start variable and at the time saved in the $end variable. All Files are chmod a+rwx . It works on command line but not in shell_exec(), also the $start and $end variables are in the correct time Format hh:mm. I found this other Post in which someone had a similar Problem but nothing posted there helped me.

if ($_POST["device"] == "Ventilator") {
    $start = $_POST["start"];
    $end = $_POST["end"];

    if ($_POST["start"] != "0") {
        shell_exec('echo "/home/pi/IOT/gpio21high.sh" | at $start');
        echo "$start".
        "<br />";
    }

    if ($_POST["end"] != "0") {
        shell_exec('echo "/home/pi/IOT/gpio21low.sh" | at $end');
        echo "$end".
        "<br />";
    }
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Michael Santos
  • 466
  • 7
  • 15
  • 1
    start by enabling error reporting and looking at your logs. You may also want to add a few `else{}` and see where that goes. – Funk Forty Niner Oct 04 '18 at 02:54
  • 1
    See also https://stackoverflow.com/questions/12199353/how-can-i-debug-exec-problems – mario Oct 04 '18 at 02:56
  • the `echo "$start". "
    ";' gets executed every time, so 'else{}' is useless , but you are right in the logfile it said "You do not have permission to use at." . i gave the .sh and the .php file 'a+rwx' rights, do you have an idea what i was missing ?
    – Michael Santos Oct 04 '18 at 03:02
  • i made a misstake while reading , the log files are old sry so thats not the problem – Michael Santos Oct 04 '18 at 03:16
  • @mario i checked every answer from the post you linked and none of these worked – Michael Santos Oct 04 '18 at 03:17
  • If you have no logs or debugging output, verify if anything got scheduled then: `atq`. Otherwise this isn't answerable I'd guess. – mario Oct 04 '18 at 03:25
  • Possible duplicate of [php shell\_exec($cmd) do not run in a cronjob](https://stackoverflow.com/q/46934471/608639) – jww Oct 05 '18 at 01:55

1 Answers1

0

It could be a great idea to execute this as a Cron job, you can execute it at a set interval etc that way.

Hope this helps thanks,

Gareth
  • 92
  • 8
  • I think it's not really suitable as cron job, as the script itself schedules "at" cronjobs. – mario Oct 04 '18 at 03:19