How can I find out, in a shell script, whether a given user name exists on the current system?
/etc/passwd and /etc/shadow are incomplete. Consider OS X's Directory Services, or Linux with Likewise Active Directory integration.
feedback
|
|
One of the most basic tools to be used for that is probably
Which produces
| |||||
feedback
|
|
|
getent This command is designed to gather entries for the databases that can be backed by /etc files and various remote services like LDAP, AD, NIS/Yellow Pages, DNS and the likes. To figure out if a username is known by one of the password naming services, simply run:
This works also with group, hosts and others, depending on the OS and implementation. | |||||||
feedback
|