Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking for a cross-platform way of determining whether or not a username and groupname is valid. The platforms are Linux, Solaris, Aix, and HPUX. It would need to work whether the user/group is defined locally (e.g. /etc/passwd) or through a service like LDAP or NIS/YP. It's probably wishful thinking that such a method exists, but it can't hurt (too much) to ask. Thanks!

Additional Info: Unfortunately I don't control the systems where this will run; the script is going out to clients and they can do whatever they want. And I don't have a way to test any of this myself...

share|improve this question

3 Answers 3

up vote 4 down vote accepted

does "getent passwd | grep " not get you anywhere ?

share|improve this answer
7  
BTW, you do not need to grep, getent passwd username works. –  ptman Oct 21 '10 at 14:39
    
Does getent hook into LDAP and NIS? –  Joe Casadonte Oct 21 '10 at 17:13
1  
@Joe At least on Solaris, getent goes through the nsswitch backend to get the data from whatever you've configured in nsswitch.conf (NIS, LDAP, /etc/* files and so on). –  alanc Oct 21 '10 at 17:22
1  
Generally, getent will hook into NIS and LDAP. getent should be calling the appropriate C library calls to pull user ID information. As long as LDAP or NIS is setup correctly on a system, the getent command will return information about those entries. –  SteveM Oct 21 '10 at 17:26
    
@ptman, yea i know :( but, but, i love grep ! –  Sirex Oct 22 '10 at 8:09

From commandlinefu:

id <username>
share|improve this answer

If not groking the flatfiles, I typically use the commands id or finger. If you have the system configured to use LDAP or NIS/YP system-wide, any command-line utility should share this functionality.

Ultimately, for your solution to be infallible, you will likely have to write more complicated logic into your script. This is a good example of why IT departments often try to prevent too many technology variances.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.