Tuesday, August 25, 2015

Force a bash script to run as root


Force a bash script to run as root






This will force your user that runs the bash script to run as root, if they are now root it will exit and not let them continue to run the script. This can be useful in many situations when writing bash scripts.




if [[ ! $(whoami) = "root" ]]; then
    echo "Please run the script as root."
    exit 1
fi

Share

& Comment

0 comments:

Post a Comment

 

Copyright © Linux Videos™ is a registered trademark.

Designed by Templateism. Hosted on Blogger Platform.