Advertisement
python_notes

Force Python script to run as Root

Jul 31st, 2014
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. euid = os.geteuid()
  5. if euid != 0:
  6.     print "Script not started as root. Running sudo.."
  7.     args = ['sudo', sys.executable] + sys.argv + [os.environ]
  8.     # the next line replaces the currently-running process with the sudo
  9.     os.execlpe('sudo', *args)
  10.  
  11. print 'Running. Your euid is', euid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement