Check to see if the user running the script is root


/ Published in: Bash
Save to your folder(s)

If you have a script that must be run as the root user, put this at the top:


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. # Test if user is root
  3.  
  4. if [ $UID -ne 0 ]; then
  5. echo "ERROR: $0 must be run as root"
  6. exit 1
  7. fi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.