Self-elevating a script to root permissions
Trick to elevate a script to root permissions
FeedbackBy Preston Hunt, 05 November 2011
I don't know why it took me so long to figure this out, but here is a nice little recipe for elevating a script to root permissions from inside the script.

#!/bin/bash

if (( UID != 0 )); then echo Re-running as root exec sudo bash $0 $* fi

echo Script is running as root echo Here are my arguments $* id

blog comments powered by Disqus