Published on Linux Journal (http://www.linuxjournal.com)
Check to see if a script was run as root
By Mitch Frazier
Created 2008-04-16 11:09

If you need to make sure a script is run as root, add the following to the start of the script:

  if [[ $UID -ne 0 ]]; then
    echo "$0 must be run as root"
    exit 1
  fi

__________________________

Mitch Frazier is the System Administrator at Linux Journal.


Source URL: http://www.linuxjournal.com/content/check-see-if-script-was-run-root-0