[Tutor] Check if root
Robert Jackson
wolf1boy85 at yahoo.com
Sat Sep 29 01:31:40 CEST 2007
I'm trying to write a function that checks to see if the user that
is running the python script is 'root' (I'm obviously running this
Python program on Linux).
Using os.system(), I have done something like this:
>>> import os
>>> os.system("whoami")
robert
0
>>>
If I try to assign the output of this snippet of code to a variable,
the variable ultimately ends up holding "0" and not the username.
I have seen some examples on Google where some individuals have suggested something like this:
user=os.system("whoami")
if user is not "root":
print "You aren't root. Goodbye."
sys.exit()
But that isn't going to work, for obvious reasons (user holds 0, and not the username). How do I get around this problem?
Robert
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/
More information about the Tutor
mailing list