Posted By

deanhouseholder on 04/16/13


Tagged

Shell Bash root


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Nix


Check to see if the user running the script is root


 / Published in: Bash
 

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

  1. #!/bin/bash
  2. #Test if user is root
  3.  
  4. if [ "$(id -u 2>/dev/null)" != "0" ]; then
  5. echo "ERROR: $0 must be run as root" >&2
  6. exit 1
  7. fi

Report this snippet  

You need to login to post a comment.