Prompting for root privlages; place at beginning of script
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
Checking for root, run as root, exit if not.
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
else
do_your_task_as_root
fi