Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Outputting group members

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
shifty_ben
LXF regular


Joined: Tue Oct 04, 2005 10:56 am
Posts: 1292
Location: Ipswich

PostPosted: Thu Apr 06, 2006 1:37 pm    Post subject: Outputting group members Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8455
Location: Warrington, UK

PostPosted: Thu Apr 06, 2006 2:34 pm    Post subject: RE: Outputting group members Reply with quote

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.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)


Last edited by nelz on Thu Apr 06, 2006 7:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
shifty_ben
LXF regular


Joined: Tue Oct 04, 2005 10:56 am
Posts: 1292
Location: Ipswich

PostPosted: Thu Apr 06, 2006 3:01 pm    Post subject: RE: Outputting group members Reply with quote

Excellent Thank you Very Happy just what I was needing, they are all in there as a secondary group so that makes life much easier Very Happy
_________________
Need a New Signature
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast