I'm trying to run a bash script from a website button on a raspberry pi, where the script is located in home/pi/. The code snippet below shows my current solution. Whenever the website button is pressed, it calls this block of code in a c file.
else if(strcmp(argv[1],"SelfTest") == 0)
{
char *command = "/bin/bash";
char name[40];
strcpy(name, "home/pi/SelfTest.sh");
execl(command, command, name, NULL);
return 0;
}
I'm running this on a Raspberry Pi 3+, the script I'm running has 777 permissions and is owned by pi:www-data, if that helps.
I tested to see if the IF block actually got called by just having it create an empty directory called 'TEST'. The bottom snippet of code shows how I approached that. This seems to work without issue (as soon as I press the button on the website, I 'ls' home/pi/ and a new folder called 'TEST' is there). Unfortunately, when I run the top snippet of code(to run SelfTest.sh), the script doesn't run (the script itself is supposed to record the output to a log file with a timestamp, and pressing the button does not update the timestamp. The timestamp only updates when I run the script from within the terminal)
else if(strcmp(argv[1],"SelfTest") == 0)
{
char *command = "/bin/mkdir";
char name[40];
strcpy(name, "/home/pi/TEST");
execl(command, command, name, NULL);
return 0;
}
What should be happening every time I press the website button is that it should run SelfTest.sh. I should be able to verify this by reading the logfile, but it never gets updated when I press the website button.
Please let me know if you need any extra information!