Check for entries in passwd file
Mon, 05/10/2010 - 00:51 — sandipCheck for entries in passwd file:
getent passwd username >/dev/null 2>&1 && echo "user exists" || echo "user does not exist"
id username >/dev/null 2>&1 && echo "user exists" || echo "user does not exist"
awk -F':' '$1 ~ /^username$/ {print $0}' /etc/passwd | grep -w username >/dev/null 2>&1 && echo "user exists" || echo "user does not exist"
- sandip's blog
- Login or register to post comments
getent to check user and group
Thu, 06/18/2009 - 17:01 — sandipTo check is user or group exist in passwd and group file:
getent passwd <user_name>
getent group <group_name>
You could also grep the corresponding files, but this is a much cleaner way of getting entries from administrative database where database is one of aliases, ethers, group, hosts, netgroup, networks, passwd, protocols, rpc, services or shadow.
- sandip's blog
- Login or register to post comments
- Read more