I have written a bash script for use on my ubuntu box. Now I would like to prevent running this script under my own user and only able to run it as root (sudo).Is there a possibility to force this. Can I somehow let my script ask for root permissions if I run it under my own username?
How do I force the user to become root
bash;permissions
I have a standard function I use in bash for this very purpose:# Check if we're root and re-execute if we're not.rootcheck () {    if [ $(id -u) != 0 ]    then        sudo $0 $@  # Modified as suggested below.        exit $?    fi}There's probably more elegant ways (I wrote this AGES ago!), but this works fine for me.