sean finney on 13 Nov 2011 13:39:46 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Finding a /etc/group entry containing a user list


On Sun, Nov 13, 2011 at 09:40:22AM -0500, Rich Freeman wrote:
> On Sun, Nov 13, 2011 at 9:24 AM,  <bergman@merctech.com> wrote:
> > Nice... or slightly more compact:
> >
> >        groups $users | cut -d: -f2-|tr " " "\012" |sort | uniq -c | sort -nr
> 
> Apparently not all groups implementations support multiple arguments
> (like the one standard on Gentoo :) ).  So, that might need to be
> tweaked on some distros.  From the very little that I've been able to
> google I'm not sure that this command is even all that standardized.

well if we're talking about being portable we probalby shouldn't be
using shell snippets but instead python/perl/C.  I don't think there's
any POSIX defined method for this (even id -Gn, which would be the
equivalent of groups, is not defined in POSIX afaik, though may be more
reliable between linuces).  Even then it only supports only one user at
a time, but that's not really such a hinderance, just a little more foo
in the shell snippet:

	for g in $(for u in $(echo $users); do id -Gn $u; done); do echo $g; done | sort | uniq -c | sort -n

arguably this is starting to stretch the boundaries of what could be called
a "one-liner" :)



	sean
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug