The problem was, that apache servers runs as a different user (www-data
) than I. Adding the user (www-data
) to /etc/sudoers
for the particular executable that needs to be run as root helped.
Why does function not get executed when called through web server?
-
28-09-2022 - |
Question
There is a python script:
#!/usr/bin/env python
import sys
import subprocess
subprocess.call("sudo /var/www/scripts/setPwm "+ sys.argv[1],shell=True)
print ("Content-type: text/plain;charset=utf-8\n\n")
print("sudo /var/www/scripts/setPwm "+ sys.argv[1])
print("ok\n")
When run locally it lights up a LED with specified intensity. When called through a website it prints all correctly, but the LED does not light up.
When I call
http://sauna/scripts/setLED.py?1000
this is printed:
sudo /var/www/scripts/setPwm 1000
ok
so the argument is apparently passed correctly, there are also no errors in apache log. Still there is no light :(
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow