Last active
June 2, 2017 18:39
-
-
Save tonejito/369ac4cb3759bf0b3471be7034a74e99 to your computer and use it in GitHub Desktop.
Get normal or system user accounts from `getent passwd` with values from login.defs
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 | |
| # get-users | |
| # Get normal or system user accounts from `getent passwd` with values from login.defs | |
| # Andres Hernandez - tonejito | |
| # | |
| # This script is released under the GPL license version 3 | |
| # | |
| # Usage: | |
| # get-users [[--]users | [--]system] | |
| AWK=/usr/bin/awk | |
| GREP=/bin/grep | |
| GETENT=/usr/bin/getent | |
| LOGIN_DEFS=/etc/login.defs | |
| UID_MIN="`$GREP ^UID_MIN $LOGIN_DEFS | $AWK '{print $2}'`" | |
| UID_MAX="`$GREP ^UID_MAX $LOGIN_DEFS | $AWK '{print $2}'`" | |
| AWK_FILTER_USERS='{if($3>=UID_MIN&&$3<UID_MAX){print}}' | |
| AWK_FILTER_SYSTEM='{if($3<UID_MIN||$3>=UID_MAX){print}}' | |
| case "${1}" | |
| in | |
| --system|system) | |
| FILTER=$AWK_FILTER_SYSTEM | |
| ;; | |
| --users|users|*) | |
| FILTER=$AWK_FILTER_USERS | |
| ;; | |
| esac | |
| $GETENT passwd | \ | |
| $AWK -F : \ | |
| -vUID_MIN="${UID_MIN}" \ | |
| -vUID_MAX="${UID_MAX}" \ | |
| $FILTER \ | |
| ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment