I want to sudo a command from a pythonscript without hardcoding my password in it. The Pythonscript is part of a webservice on Apache2. Since it is part of a webservice, asking the user each time for the password is not an option, neither is giving full rights to the entire folder.
The command should execute a compiled C++ file (whose name is stored in the variable "CMDexecutable"). This compiled C++ file is located in a temporary folder that is being created as part of the service with a random name. The path is stored in the variable "rundir_temp". This directory is freely accessable over the web.
Now, I have the following in my Pythonscript :
Popen(os.path.join(rundir_temp,CMDexecutable),stdout=PIPE)
This does not execute the script I have. I can only execute the compiled C++ file by typing the following in the terminal while in the "rundir_temp" directory:
sudo ./CMDexecutable
Everything works perfectly then.
How can I give sudo rights to this command in my Pythonscript without hardcoding my password?
I found this thread which discusses a very similar topic, but I just can't get it working... I'm new to both Python and Ubuntu, so probably overlooking a basic thing?
I have Ubuntu 14.04 LTS and Python 2.7.6
Thanks in advance!!