Monday, June 29, 2009

HOWTO Check if a user or group already exists

Dont directly check with /etc/passwd, or /etc/group for existence of a user or group. This wont look up NIS database entries. A better way is to use getent, part of glibc. Lookup database entry for an existing user:
getent passwd username1 [username2 ...]
Lookup database entry for an existing group:
getent group groupname1 [groupname2 ...]

Identifying Linux distributor and version

The Linux Standard Base makes it really easy to identify the Linux distributor and version for LSB compliant. If the lsb package is installed (redhat-lsb, lsb, asianux-lsb, ...), just run:
lsb_release -i -d
or
lsb_release -a