Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Finding all users of a group
iw_store
Hi ALL,
Is there any command is there in UNIX to find all the users of group.
This can be done by greping and all.
But if any command is there to get directly please tell me.
Sanjeev.
Find more posts tagged with
Comments
gzevin
I don;t think so. In workflows one writes a function.. it'll depend on how the groups are implemented. It would be either a simple processing of /etc/groups or a query to a directory server
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
iw_store
Hi,
Thanks, i have done that, i feel that is inconsistent, hence i asked any command to find directly or any other way which i can i do in a consistent way.
Sanjeev.
gzevin
what inconsistency do you see there?
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
iw_store
Hi,
If i use gerp it fails under circumstances like, take for example i have a group name "other" i fire GREP other on /etc/group if there are groups like iwotherbtw some think randomnly like that it considers this also.
If a read line by line and compare with somethink and split and get what i what want it slows downs the program execution.
And one more issue is on Production Box all user do not have access to /etc/group to do above.
Sanjeev.
Adam Stoller
Basically:
cat /etc/group | awk -F: '{print $1}' | grep -v '#' | sort
or:
perl -le 'print sort(map{ s/:.*$//; $_ } grep {\!/\#/} <STDIN>)' < /etc/group
or - in code form:
my
@groups
;
if (open(IN, '<', "/etc/group")){
@groups
= map { chomp; s/:.*$//; $_ } grep { !/\#/ } <IN>;
close(IN);
}
print join("\n", sort(
@groups))
. "\n";
It's possible that some flavors of Unix might provide commands for doing this (AIX I believe has an
lsgroup
command) - but in general, and for portability the above two commands will work
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
iw_store
Hi Ghoti,
Very Help gul Lines of code, thank you very much, i tested first two they give all the groups which are there in /etc/group file.
What i want is users of a particular group.
For Exaple my group is sys [sys::3:root,bin,sys,adm] it should give me corresponding users means root, bin, sys, adm.
Mine is sunsolaris 8 box.
Sanjeev.
nipper
The problem with Ghoti's approach is that it will find all the users who have the secondary group as Blah
but not the primary group.
in /etc/passwd you define the primary group so you need to search there as well.
should be a simple regex to look for it. I think the form is:
username:encodedpasswd:UID:GID:Comment:home dir:shell
so you get the GID from /etc/groups. the find all users that have that GID in the /etc/passwd
HTH
Andy
gzevin
Well, I have not heard from you about the context in which you need to grep the group, so I cannot elaborate on that. However, I can't see any reason why a code is slow provided this is a basic perl operation and the computers are extremely fast these days......
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU