logging as root using python script

Luis Bruno lbruno at republico.estv.ipv.pt
Thu Apr 7 05:50:48 EDT 2005


Raghul wrote:

> What I need is when I execute a script it should login as root and
> execute my command and logout from root to my existing account.

I'm not sure of what you need, so I'll assume your *whole* .py script
needs root priviledges. In this case, you can configure sudo(8) or use
su(1).

For example, the script below does nothing special:

| #!/usr/bin/env python
| 
| print "Hello world!"

You can run it with higher priviledges if you use sudo(8):

$ chmod 755 hello.py
$ sudo ./hello.py

Or you can use su(1):

$ su - root -c ./hello.py

You can configure sudo(8) to not prompt for any password, BTW.

Cheers!
-- 
Luis Bruno



More information about the Python-list mailing list