users per group


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting users per group
# 1  
Old 04-12-2010
users per group

hi guys

I am trying to display a list of groups and the respective users:

Group1 : user1 user2 user3 ....

the closest thing I get is
Code:
echo " "; echo "Group       Users   "; echo " "; cat /etc/group |grep [5-9][0-9][0-9] | grep -v nfs

which I really don't since I want to remove the other stuff like x : and the group ID

something like I wrote before

Group1 : user1 user2 user3 ....
Group2 : user1 user4 user5 ....

thanks a lot
# 2  
Old 04-12-2010
You could try this for the secondary groups
Code:
awk -F: '/[5-9][0-9][0-9]/{print $1" : "$4}' /etc/group

But note that you have to get primary group info from /etc/passwd.
# 3  
Old 04-12-2010
MySQL

you can try this
Code:
cat /etc/group | grep -v "^.*:$" | sed 's/\([a-zA-Z][a-zA-Z]*\):x:[0-9][0-9]*:\(.*\)/\1 : 2/'

# 4  
Old 04-12-2010
A method which includes primary groups. Assumes you have the unix "logins" command. Script allows for more than one line in /etc/group for the same group (which can happen).

Code:
#!/bin/ksh
awk -F: '{print $1}' /etc/group| sort | uniq |while read GROUP
do
    USERLIST=$( logins -g "${GROUP}" | awk '{print $1}' | sort |tr '\n' ' ' )
    echo "${GROUP} : ${USERLIST}"
done

# 5  
Old 04-12-2010
Quote:
Originally Posted by Scrutinizer
You could try this for the secondary groups
Code:
awk -F: '/[5-9][0-9][0-9]/{print $1" : "$4}' /etc/group

But note that you have to get primary group info from /etc/passwd.

thanks a lot I think this one does what I need Smilie

Code:
awk -F: '/[5-9][0-9][0-9]/{print $1" : "$4}' /etc/group | grep -v nfs

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Users of own group shouldn't be able to delete

Oracle Linux 6.5 oracle user's primary group is oinstall and its secondary group is dba,asmdba,asmoper. For the below created directory, I want the users belonging to dba,asmdba,asmoper to be able create, read and execute files but not delete them. How can I achieve that. If I use 775 as... (5 Replies)
Discussion started by: kraljic
5 Replies

2. Programming

to obtain users of each group in c

Hello They have ordered to me that makes several small utilities in C/C++ for the servants, among them a small program in C/C++ to generate a file HTML with the groups of that servant and in addition that is the corresponding users of that group. For example of a group: Group: Sys Members:... (2 Replies)
Discussion started by: cybermeis
2 Replies

3. Shell Programming and Scripting

Change of group to different users

Need to change the chgrp for different uses d---rwx--t 3 root 764 4096 Mar 16 2007 algavi d---rwx--t 6 root 2857 4096 Jul 16 11:28 alharki d---rwx--t 5 root 2739 4096 Oct 14 2008 alpen d---rwx--t 5 root 546 4096 Mar 16 2007 alvarez d---rwx--t 3 root... (2 Replies)
Discussion started by: gsiva
2 Replies

4. Shell Programming and Scripting

Diffferentiate group from users

Im trying to put all the groups in into a variable called $GROUP, however in /etc/group there are also lotsa users. And the GID of group can differ as it can be set, this there is no specific range, how can i put all the names of the groups into that variable? (3 Replies)
Discussion started by: dplate07
3 Replies

5. Solaris

How can i allow only a group of users in NIS?

Hello experts. I am using Solaris10. How can i allow a group of users, remaining should be deny. Thanx in advance. (9 Replies)
Discussion started by: younus_syed
9 Replies

6. Shell Programming and Scripting

SSH for a group of users ?

Hi, Can any one tell me is it possible to setup private key public key pairing(SSH ) for a group of users , instead of setting it up for individual users ? Eg: Say i have 3 users A,B and C and i want the users to connect to SERVER1. instead of generating public private keys for each user , is... (3 Replies)
Discussion started by: deepusunil
3 Replies

7. Shell Programming and Scripting

Sending an email to group of users

Hi , I want to write a Unix script which can send an automatic email to the group when my job is completed.I'm trying the following Mail -s "test" <groupname> << EOD >Completed >EOD With this i'm not able to send an email to group..Any ideas? Thanks in Advance (1 Reply)
Discussion started by: BhawanaAggarwal
1 Replies

8. AIX

Max users in a group ?

Hi All, Does anyone know if there is a maximum limit to the number of users that can be assigned to a group. I currently have on a production server 900+ users in 1 group. I know some of these users are no longer valid as we only have 500 employees and not all employees use this application. ... (4 Replies)
Discussion started by: anmiller
4 Replies

9. Solaris

How do you list users in a solaris group

I need to list all users in a group. This is a large unix site running nis+. (6 Replies)
Discussion started by: gillbates
6 Replies

10. UNIX for Dummies Questions & Answers

Adding users to /etc/group

I'm using SAM to add users on an HP and they're adding fine. But in /etc/group it only lists the group names. It's not adding the users in there. Is there a way to have them put in there without going into SAM and modifying the group and adding them? I guess what I want to happen is when I add... (1 Reply)
Discussion started by: golfhakker
1 Replies
Login or Register to Ask a Question