Created
September 21, 2013 18:55
-
-
Save PerpetualBeta/6653157 to your computer and use it in GitHub Desktop.
Bash script header to elevate a script that needs to run as "root" if it is run without sudo. Background here: http://darkblue.sdf.org/weblog/post/got-root
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /bin/sh | |
if [ "$(whoami)" != 'root' ]; then | |
echo 'This script must be run as "root".' | |
echo 'Enter password to elevate privileges:' | |
SCRIPTPATH=$( cd $(dirname $0) ; pwd -P ) | |
SELF=`basename $0` | |
sudo $SCRIPTPATH'/'$SELF | |
exit 1 | |
fi | |
clear | |
echo 'Script running with root privileges.' | |
# Your code here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment