|Running a Python script with root permissions|
|FeedbackBy Preston Hunt, 07 November 2013|
This works fine for shell scripts, but recently I needed a way to do this for Python scripts. The trouble is that the shebang #! syntax only allows limited command-line argument passing.
This following recipe is not pretty, but it seems to work!
if (( UID != 0 )); then echo re-running as root exec sudo -E "$0" "$@" fi
python2 -u <(cat <<"EOF" print "hello, world!" EOF ) "$@"
blog comments powered by Disqus