[Tutor] iPython check if user running script is root user (Linux)

Emile van Sebille emile at fenx.com
Fri Jun 1 00:30:28 CEST 2012


On 5/31/2012 3:21 PM Dave said...
> Hi. What is the right way to have an iPython script check to see if the
> user is currently root?

Googling for "python check if user is root" yields the answer:


import os, sys

# if not root...kick out
if not os.geteuid()==0:
     sys.exit("\nOnly root can run this script\n")


See 
http://code.activestate.com/recipes/299410-root-access-required-to-run-a-script/

Emile



More information about the Tutor mailing list