Check for root access in a bash script
Handy bit of code to add at the start of your bash script if you need to check for root access:
# Do we have root access?
if [[ $(/usr/bin/id -u) -ne 0 ]];
then echo "Sorry, this script needs to run with root or sudo access"