[Fedora-packaging] Possible UsersAndGroupsDraft

Jarod Wilson jwilson at redhat.com
Thu Jun 14 18:24:05 UTC 2007


Simo Sorce wrote:
> On Thu, 2007-06-14 at 10:44 -0400, Jarod Wilson wrote:
>> # getent passwd | cut -d: -f1 | grep -c <user>
>>
>> # getent group | cut -d: -f1 | grep -c <group>
> 
> It is advised to query the specific name required, the posix
> specification allow for backends not to reply all or any of the accounts
> in the db. But you have to replay if a specific user/group is requested.
> 
> On very large environments (nis, ldap, winbindd) listing all the
> accounts and then grepping out the one you need is a complete waste of
> resources anyway and also a possibly very, very long operation.
> 
> so the right method might be:
> 
> getent passwd <user> >/dev/null
> getent group <group> >/dev/null
> 
> if the user/group exist then 0 is returned if not then non zero (2 iirc)
> is returned

That is indeed a superior way to go, and you're correct on the exit
values. And 'getent' seems slightly more flexible than 'id' when it
comes to finding out about groups, at least at a glance.

-- 
Jarod Wilson
jwilson at redhat.com


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/fedora-packaging/attachments/20070614/cc7fde19/attachment.sig>


More information about the Fedora-packaging mailing list