So, on a Raspberry Pi I’m using a camera app with a web interface, I wanted to add LED lighting by adding a neopixel. I have successfully done this and can now turn it on and off running two python scripts.
Explanation and question:
I have a python script in /usr/local/bin
that is executable.
It is owned by ‘root root‘.
I have a shell script in /var/www/html/macros
that is executable and has to run the python script in /usr/local/bin
.
The shell script is owned by ‘www-data‘
When I manually run the python file, it executes the script.
When I manually run the shell script, it executes the python script.
When I run the shell script by clicking on a button on my webpage, it seems to execute the shell script correctly, however, it looks like it doesn’t execute the python script.
What can I do to fix this?
I’m not that experienced with permissions, but I wanted to emphasize on the fact that this is a closed system that does not contain any sensitive information. So safety/best practice is not a concern. I just want to make this work.
2
Answers
Now, after 11 hours and a group of people thinking along we found a solution to the problem.
The problem turned out to be that the Web interface can only execute as 'www-data', and the NeoPixel library that the python script depends on needs to be executed as sudo/root.
These two factors make it so that there will never be a direct way of getting the scripts to work together.
However, the idea emerged to use some sort of pipe.
A brilliant user suggested to me to use sshpass. This would allow to pass data to ssh and have it essentially be executed as a root user.
The data from the web interface would be relayed to the sshpass and this would successfully run the needed scripts with the needed privileges.
Special thanks to Minty Trebor and Falcounet from the RRF for LPC/STM Discord!
I’m not an expert in this area, but I believe to access
/usr/local/bin/
you needroot
privileges which explains why you’re having success but not Apache.Rather than give Apache
root
permissions, it’s best to simply remove the requirement from the individual file you want to execute. This can be accomplished by