- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- get userlist from HPUX whose primary group is give...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 12:26 AM
тАО07-04-2006 12:26 AM
get userlist from HPUX whose primary group is given
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
- Tags:
- getgrnam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 12:31 AM
тАО07-04-2006 12:31 AM
Re: get userlist from HPUX whose primary group is given
For example GID= bin :
cat /etc/passwd|grep ":2:"
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 12:38 AM
тАО07-04-2006 12:38 AM
Re: get userlist from HPUX whose primary group is given
thread http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=849713 shows how to get the reverse of the info without C.
So for your case,
get the gid for "adm_system" from /etc/group then look in /etc/passwd for this gid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 12:44 AM
тАО07-04-2006 12:44 AM
Re: get userlist from HPUX whose primary group is given
Have you tried the logins command:
# logins -g
For more info see man logins.
Darrel
- Tags:
- logins
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 01:20 AM
тАО07-04-2006 01:20 AM
Re: get userlist from HPUX whose primary group is given
#include
#include
main()
{
int i=0;
struct group* grp;
struct passwd* pwd;
grp = getgrnam("adm_system");
if(grp)
{
printf("Group Name %s\n",grp->gr_name);
printf("GRPID %d\n",grp->gr_gid);
while (grp->gr_mem[i] !=NULL)
{
printf("Users from Group file : %s\n",grp->gr_mem[i]);
i++;
}
while (pwd=getpwent())
{
if (pwd->pw_gid == grp->gr_gid) printf("Users from Password file : %s\n",pwd->pw_name);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 01:57 AM
тАО07-04-2006 01:57 AM
Re: get userlist from HPUX whose primary group is given
do you really need to programm it by yourselfe? There is a tool in HP-UX called "logins" that allready does what you want.
Do you just need the information? Then logins should be helpfool to you.
Or do you need a function in your own programs?
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 03:56 AM
тАО07-04-2006 03:56 AM
Re: get userlist from HPUX whose primary group is given
I missed the fact you could me using NIS...
In this case as suggested the use of logins -g
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 09:25 AM
тАО07-04-2006 09:25 AM
Re: get userlist from HPUX whose primary group is given
The standard libc passwd and group file functions will automatically include the NIS data, if applicable.
#include
#include
int main()
{
struct group *grp;
grp = getgrnam("adm_system");
if(grp != NULL)
{
struct passwd *pwd = NULL;
printf("Group Name %s\n",grp->gr_name);
printf("GRPID %d\n",grp->gr_gid);
do
{
pwd = getpwent;
if (pwd != NULL)
{
if (pwd->pw_gid == grp->gr_gid) printf("%s\n",pwd->pw_name);
}
}
while (pwd != NULL);
}
return(0);
}