Re: Possible UsersAndGroupsDraft

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

 



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@xxxxxxxxxx


Attachment: signature.asc
Description: OpenPGP digital signature

--
Fedora-packaging mailing list
Fedora-packaging@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-packaging

[Index of Archives]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Forum]     [KDE Users]

  Powered by Linux