Last active
July 7, 2016 11:20
-
-
Save zhmurko/48ed3e12de44bf629df212fff0aae9bd to your computer and use it in GitHub Desktop.
List all normal user and system accounts in the system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Name: listusers.bash | |
# Purpose: List all normal user and system accounts in the system. Tested on RHEL / Debian Linux | |
# Author: Vivek Gite <www.cyberciti.biz>, under GPL v2.0+ | |
# ----------------------------------------------------------------------------------- | |
_l="/etc/login.defs" | |
_p="/etc/passwd" | |
## get mini UID limit ## | |
l=$(grep "^UID_MIN" $_l) | |
## get max UID limit ## | |
l1=$(grep "^UID_MAX" $_l) | |
normal_users() { | |
## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin ## | |
echo "----------[ Normal User Accounts ]---------------" | |
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max && $7 != "/sbin/nologin" ) print $0 }' "$_p" | |
} | |
system_users() { | |
echo "----------[ System User Accounts ]---------------" | |
awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( !($3 >= min && $3 <= max && $7 != "/sbin/nologin")) print $0 }' "$_p" | |
} | |
case "$1" in | |
"--all") | |
system_users | |
echo "" | |
normal_users | |
;; | |
"--normal") | |
normal_users | |
;; | |
"--system") | |
system_users | |
;; | |
*) | |
echo $"Usage: $0 [--all|--system|--normal]" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment