How do I find out if a uid exists?
I have added a new user in Ubuntu using puppet with a hard coded uid of 10017. The uids must be the same across workstations so that when user data is restored everything lines up.
Now I find out that uid is not unique. Mysql is using it. How can I test a server to find out if a uid (10018) exists?
Answering the specific question (how do I tell if a uid is in use) ...
getent passwd 1234
Will exit with 0 if uid is in use and 2 if not. As Mark says it will also output any matching entries. When using within a shell script I'd expect to discard the output and just test the exit code.
Note that using getent
has the advantage of any techniques that look at /etc/passwd
directly because it will also consult any other data sources you have configured (NIS, LDAP etc).
cat /etc/passwd | awk -F: '{print $3}' | sort -n