Is there an easy way to get a list of users who are in all specified groups?
For example, if I have the following users:
fred - rainbow, dell
jane - hp
zippy - rainbow, hp, dell
george - hp, dell
bungle - rainbow, hp, dell
I would like something like this:
[me@box ~]$ magic "dell,hp"
zippy, george, bungle
ie returning the users who are in both dell and hp.
If it is multiple steps that is fine, though if it's not really possible without having to resort to lots of Bash black magic, and it is quicker to do it in a RE-enabled text editor that is also fine.
I'm running on RHEL4 if that makes any difference.
This works for two groups at a time:
Put it in a function with some modifications and it will handle any number of groups:
Run it:
A function consisting mostly of an AWK script:
I don't known any tool doing this but it is easy to script.
At first get the list of the users on the system, then run
groups
on each and at the end,grep
on the desired groups :Small python script:
Test:
A bash solution that takes more than 1 user per line and print only unique groups. Normal output is one grop per line, use
-c
to get the output separated by commas.Example output:
Using
-c
: