I have a Python script that automatically has to trigger a shell script.
Everything works fine but there is one problem. When I execute the script (from a webinterface) the terminal where the process runs under will ask for the password of the user. This shouldn't be asked and should automatically connect with with sudo
rights.
os.system("chmod +x " + pathInstallScript)
os.chdir(installerLocation)
#The problem happens here.
subprocess.call(['sudo','./'+ self.file_to_execute])
The subprocess.call works fine. It will find the path and starts but then the sudo
kicks in. The sudo call will ask for the user its password before it continues. When I manually enter the password in the terminal everything will work fine but I have to by-pass this.
What I've tried:
cmd = ['sudo', './'+ self.file_to_execute]
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.stdin.write('MyPassword\n')
proc.stdin.flush()
But that doesn't seem to pass the password in. My second attempt:
proc = subprocess.Popen(
['sudo','./'+ self.odoo_username],
stdin=subprocess.PIPE)
proc.stdin.write('odoo\n')
proc.stdin.close()
proc.wait()
But no succcess either. So how can I pass the password within this call so I don't have to manually authenticate?
Note: I do know that placing user password in files is not secure and frowned up on. In the next step my password will be provided from the database and won't be up for grabs in any single way!