1830565 Members
4960 Online
110014 Solutions
New Discussion

groups

 
SOLVED
Go to solution
grennepois johann
Occasional Contributor

groups

Hello,

I'd like to display the list of members within a groups.

I used the following instruction:

grep $1 /etc/group | nawk -F: '{print " ",$4}'

that gives me the list of ids but I would like
to get users identity with a mix of /var/yp/src/passwd content.


Thanks for your help.
5 REPLIES 5
Rodney Hills
Honored Contributor

Re: groups

For a given group name you can fetch the group id number by-
grpid=`awk /^$1:/{print $3}`

Then to get the list of users for that group (users that are defined in NIS)-
ypcat passwd | awk -F: -v gid=$grpid '$4==gid{print $1}'

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor
Solution

Re: groups

I messed up on that first assignment-

It should be-

grpid=`ypcat group | awk -F: -v grp=$1 'grp==$1{print $3}'`

-- Rod Hills

There be dragons...
grennepois johann
Occasional Contributor

Re: groups

Hello,


thanxs for your answer and help.
I tried your solution. It works but not totally what U expected.

In fact using "ypcat passwd" not give the groups I want, I had to use /etc/group that contains all created groups.

so I use cat /etc/group instead of ypcat group.

But the problem is the ouput. The output from your instruction is the group id. Is there a file in which we have the list of groups that belongs to a user???

If I use the uid parameter in output, I have the list of user within the group with the following format uid1,uid2,uid3 so using the second instruction to get users name, it does not match.

Do you see my new pb?

Thanx by advance.

Regards,

Johann

Re: groups

Did you want something like this ?

cat /etc/passwd | cut -d: -f1 | while read user
do
echo "$user: \c"
groups $user
done

You can of course replace 'cat /etc/passwd' with 'ypcat passwd' if you need to...

HTH

Duncan

I am an HPE Employee
Accept or Kudo
grennepois johann
Occasional Contributor

Re: groups

Thanx for your help Duncan.

In fact Rodney solution was quite the one I expected.

I would like to create a script "toto groupname" that gives me the list of the users that belong to the groupname. Not their ID but their complete identity from passwd file.

Rodney proposed in the 1st instruction to check group id in group file. As for me, this file does only contain system groups, for my use I need to work with /etc/group file.

The proposed solution refers to group id in order to check users' identity within passwd. But passwd file does not seem to list all groups for a user.

So, in my tests, I tried to select the userid's list instead of groupid and then to link each uid to the required line in passwd file. But I don't know how. Because the result of the 1st instruction is uid1,uid2,uid3...

I think it would be possible with a do instruction but my knowledeges are limited in UNIX environment.

Thanx by advance for any help.

Regards,

JG