Skip to content

Instantly share code, notes, and snippets.

@spchamp
Last active April 20, 2020 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spchamp/fadb088c46e2e397a451ce462b54a352 to your computer and use it in GitHub Desktop.
Save spchamp/fadb088c46e2e397a451ce462b54a352 to your computer and use it in GitHub Desktop.
print a list of a auxiliary groups assigned to a single user name, using getent(1)
# getent_auxgroups.sh - print auxiliary groups assigned to a single user name
#
# % Environment parameters
# WHOM
# - user name to parse for
# - If unspecified, defaults to $USER
# - Will be interpreted within a regular expression, in awk(1)
#
# % Depends On
# - getent(1)
# - awk(1)
#
# % See Also
# - pw(8), FreeBSD System Manager's Manual
#
# Public Domain
#
getent group |
awk -v UNAME="${WHOM:-${USER}}" \
'BEGIN { FS=":" }
{ split(4,subfield,/,/);
for (idx in subfield) {
if (match($subfield[idx],"^" UNAME "$")) {
print $1
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment