Skip to content

Instantly share code, notes, and snippets.

@tonejito
Created January 28, 2013 20:27
Show Gist options
  • Save tonejito/4658702 to your computer and use it in GitHub Desktop.
Save tonejito/4658702 to your computer and use it in GitHub Desktop.
./belong.sh - Get all users in group
#!/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