I've used something like this successfully in the past: import commands if commands.getoutput( "whoami" ) != "root": sys.exit( "Must be root!" )
Hope this helps. .james On Sep 28, 2007, at 7:31 PM, Robert Jackson wrote: > 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/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor