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

Chris Rebert clp2 at rebertia.com
Tue Feb 24 20:44:16 CET 2009


On Tue, Feb 24, 2009 at 11:38 AM, madhav <madhav.bnk at gmail.com> wrote:
> 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?

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

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list