Guest_imported
New member
- Jan 1, 1970
- 0
How would I find the groups for 4 users? I can type in the 'group' commandfor myself but want to build a script that will give me each persons name and all the groups they are in.
I am on a Solaris 7 os.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#!/bin/ksh
nawk -F: '
BEGIN {
# Populate the GECOS and primary
# group ID arrays.
while (getline < "/etc/passwd") {
if ($5 == "") {
GECOS[$1]=$1
} else {
GECOS[$1]=$5
}
pgid[$1]=$4
}
close "/etc/passwd"
}
function printuser(user) {
if (user in GECOS) {
if (GECOS[user] == "") {
# Handle /etc/passwd entries with blank
# GECOS field.
print " " user
} else {
print " " GECOS[user]
}
} else {
print " WARNING: User \"" members[i] "\" does not exist in /etc/passwd."
}
}
{
gid=$3
print $1 " group members:"
split($4,members,",")
# Print users for whom this is the primary group.
for (user in GECOS) {
if (! (user in members) && pgid[user] == gid) {
printuser(user)
}
}
# Print users for whom this is a supplementary group.
for (i in members) {
printuser(members[i])
}
print ""
}
' /etc/group