Operating System - HP-UX
1834798 Members
2963 Online
110070 Solutions
New Discussion

Re: get the user list whose primary group is given from HPUX box.

 
pjena
Occasional Contributor

get the user list whose primary group is given from HPUX box.

Hi,
I want to get the username list whose primary group is given on HPUX.
I used following program to get the username

main()
{
int i=0;
struct group* grp;
grp = getgrnam("adm_system");
if(grp)
{
printf("%s\n",grp->gr_name);
printf("%s\n",grp->gr_passwd);
printf("%d\n",grp->gr_gid);
while (grp->gr_mem[i] !=NULL)
{
printf("%s\n",grp->gr_mem[i])
i++;
}
}
}
But it is displaying the user list whose secondary group is "adm_system" and also tried with getgrgid(), but it doesn't give the proper result.

Please help me to get the user list whose primary group is "adm_system"

Regards,
Prasant
7 REPLIES 7
Jaime Bolanos Rojas.
Honored Contributor

Re: get the user list whose primary group is given from HPUX box.

pjena, unless I misundestood you... the way that I would do it is to first find the group id for "adm_system".
Then with that in hand, I would a simple cat /etc/passwd | grep -i adm_system since in the etc/passwd file you will only find the primary group listed for each user.

Hope this help you out.

jaime.
Work hard when the need comes out.
Jaime Bolanos Rojas.
Honored Contributor

Re: get the user list whose primary group is given from HPUX box.

pjena, unless I misundestood you... the way that I would do it is to first find the group id for "adm_system".
Then with that in hand, I would do a search for that ID in the group field of the passwd file and it will give you a list of the users that belong to adm-system.

Hope this help you out.

jaime.
Work hard when the need comes out.
pjena
Occasional Contributor

Re: get the user list whose primary group is given from HPUX box.

Hi Jaime,
Thanks for replying to my query.
I think in NIS implementation, /etc/passwd will not give the proper answer.

If there is some direct system API, then it would be great.

Regards,
Prasant
Darrel Louis
Honored Contributor

Re: get the user list whose primary group is given from HPUX box.

Hi Prasant,

Have you tried the logins command:
# logins -g

For more info see man logins.

Darrel
Peter Nikitka
Honored Contributor

Re: get the user list whose primary group is given from HPUX box.

Hi,

in your code change from the while statement on to scan the passwd database (does only depend on the entry in nsswitch.conf) something linke this:

setpwent()
while (pw = getpwent()) {
if (!strcmp(pw->pw_gid,grp->gr_gid)) {
do_my_output(...)
}
endpwent();
...

Read 'man getpwnam' and 'SEE ALSO's as well.

mfG Peter

The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Jaime Bolanos Rojas.
Honored Contributor

Re: get the user list whose primary group is given from HPUX box.

OK, did some search already.

The best way to do will be using the ypcat group command and then scramble the data from there.

For a more detailed information, this thread might be able to help you out.

http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=27514

Regards,

Jaime.
Work hard when the need comes out.
Peter Nikitka
Honored Contributor

Re: get the user list whose primary group is given from HPUX box.

Hi,
correction:
of cource the id's are numeric, so you don't need to compare strings:

setpwent();
while (pw = getpwent()) {
if (pw->pw_gid == grp->gr_gid) {
do_my_output(...)
}
endpwent();
...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"