Run a linux system command as a superuser, using a python script

M

madhav

I have got postfix installed on my machine and I am updating on of its
configuration files programmatically(using python)(on some action).
Since any change in the configuration needs a reload, I need to reload
postfix to reflect the latest change. How can I do that in a python
script. Precisely, I have something like this:

import subprocess
subprocess.Popen('sudo /etc/init.d/postifx reload')

Since this script should be run in no-human environment(on the fly), I
cant supply the sudo password or even root password(if needed). Even
sudo doesn't have a flag to input the password for the command at the
first shot. How do I do this?
 
B

birdsong

pexpect may be useful in this situation -http://www.noah.org/wiki/Pexpect

Cheers,
Chris

I vote down the pexpect, you'd be hardcoding a password. How about
adjusting the sudoers file to grant the user of this script sudo on /
etc/init.d/postifx or even sudo on your python script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top