Tuesday, 25 January 2011

Finding out users in groups

In a UNIX / Linux environment, it may be useful to determine who is in a group. The following line will determine who is in a group, and pull out their information based on the finger protocol:

for i in $(cat /etc/group|grep -i insert_group_name_here|cut -d ":" -f 4|sed 's/,/ /g'); do echo "################"; echo "";finger $i; echo"";done

This looks like:

$ for i in $(cat /etc/group|grep -i mygroup|cut -d ":" -f 4|sed 's/,/ /g'); do echo "################"; echo "";finger $i; echo"";done
################


Login name: smithjrr In real life: 6116
Site Info: A/E/John Smith
Directory: /home/smithjrr Shell: /usr/bin/ksh
No Plan.

################

Login name: mywasguy In real life: 6116
Site Info: C/K/L/Web App Server Admin
Directory: /home/mywasguy Shell: /usr/bin/ksh
No Plan.

################

Login name: ric In real life: 6116
Site Info: E/I/ric_man
Directory: /home/ric Shell: /usr/bin/ksh
On since Jan 25 11:17:22 on pts/0
No Plan.

Your results may vary depending on how the information is stored.

No comments:

Post a Comment