Created
January 28, 2013 20:27
-
-
Save tonejito/4658702 to your computer and use it in GitHub Desktop.
./belong.sh - Get all users in group
This file contains 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/sh | |
# = ^ . ^ = | |
# | |
# ./belong.sh - Get all users in group | |
# Andres Hernandez (tonejito) | |
# http://tonejito.blogspot.com:80/ | |
SED=/bin/sed | |
AWK=/usr/bin/awk | |
GETENT=/usr/bin/getent | |
GROUP=${1} | |
# Find users whose initial login group is $GROUP | |
$GETENT passwd | awk -F : "\$4==`$GETENT group $GROUP | awk -F : '{print $3}'` {print \$1}" | |
# Find users whose supplementary group is $GROUP | |
$GETENT group $GROUP | $AWK -F : '{print $4}' | $SED -e 's/,/\n/g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment