python - differentiate sudo <command> and <command> -


i make user run sudo , normal user depending on choice.he use sudo or normal on not using sudo have disable functionalities rid of errors.so how know user given me sudo permissions execute or not? building application on python.

after having read question few times, think know asking. correct in thinking want know how tell whether or not python script root permissions during runtime?

if want check ahead of time, query system user id os.geteuid() , if returns 0, script running root.

however, alternative approach run code needs root privileges in try block. depending on trying do, may or may not better solution. have know type of exception expect if don't have needed privileges. makes little harder write code may end more flexible changing circumstances, such users enough privileges not root. may make more portable code, although exception may change 1 os another.

e.g.

try:     function_that_needs_root() except mynotrootexception:     print "skipping function_that_needs_root: not root" 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -