How do you find the users that are in a unix group (not what groups a
user is in: `groups`), based on their primary /etc/passwd gid and
/etc/group contents?

Been reading obscure Oracle docs and found this in the OFA paper and
thought "surely there's a command for that" (it was written in '93)

#!/bin/sh #
# grpx - print the list of users belonging to a given group
# Cary Millsap, Oracle Services
# @(#)1.1 (93/07/04)

prog=`basename $0`
if [ $# -ne 1 ] ; then
        echo "Usage: $prog group" >&2
        exit 2
fi

g=$1
# calculate group id of g
gid=`nawk -F: '$1==g {print $3}' g=$g /etc/group`
# list users whose default group id is gid
u1=`nawk -F: '$4==gid {print $1}' gid=$gid /etc/passwd`
# list users who are recorded members of g
u2=`nawk -F: '$1==g {gsub(/,/," "); print $4}' g=$g /etc/group`
# remove duplicates from the union of the two lists
echo $u1 $u2 | tr " " "\012" | sort | uniq | tr "\012" " "
echo


Paul

-- 
Change specifics to ambiguities

Reply via email to