| View previous topic :: View next topic |
| Author |
Message |
shifty_ben LXF regular

Joined: Tue Oct 04, 2005 10:56 am Posts: 1292 Location: Ipswich
|
Posted: Thu Apr 06, 2006 1:37 pm Post subject: Outputting group members |
|
|
Hi all,
Im currently writing a CLI frontend to manage my webserver, it has a few users on it that are all members of the group webhosting. What I seem to have come stuck on is building an offline 'database' of this, the reason database is in apostraphies is because it will jsut be a text file with the relevant details in.
I can't seem to find any way of running a command that will output all the users in a specific group, in this case webhosting.
Im using BASH for the rest of the frontend but if any suggestions are in other languages then I should be able to incorporate that.
Any ideas?
cheers
Ben _________________ Need a New Signature |
|
| Back to top |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 7993 Location: Warrington, UK
|
Posted: Thu Apr 06, 2006 2:34 pm Post subject: RE: Outputting group members |
|
|
If they are members of webhosting ass a secondary group, you can grep this information from /etc/group
| Code: | | grep ^${GROUP} /etc/group | cut -d: -f4 |
To find those that are members of the group as their primary group, you'd have to convert the group name to a numeric ID then grep /etc/passwd.
| Code: | GID=$(grep ^${GROUP} /etc/group | cut -d: -f3)
egrep ".*?:.*?:.*?:${GID}:.*" /etc/passwd | cut -d: -f1 |
should do it, although some error checking might be a good idea. _________________ Unix is user-friendly. It's just very selective about who it's friends are.
Last edited by nelz on Thu Apr 06, 2006 7:52 pm; edited 1 time in total |
|
| Back to top |
|
 |
shifty_ben LXF regular

Joined: Tue Oct 04, 2005 10:56 am Posts: 1292 Location: Ipswich
|
Posted: Thu Apr 06, 2006 3:01 pm Post subject: RE: Outputting group members |
|
|
Excellent Thank you just what I was needing, they are all in there as a secondary group so that makes life much easier  _________________ Need a New Signature |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|