Chapter 28. check_for_stray_users_in_etc_group.sh

#!/bin/sh

# for each user that's listed as a group member, make
# sure there is corresponding /etc/passwd entry


for USER in `cat /etc/group|cut -d: -f4|tr , '\n' |sort|uniq|grep -v '^$' `
do
if ! grep ^${USER}: /etc/passwd >gt; /dev/null; then echo $0 found stray user ${USER} in /etc/group. ; fi
done | xargs echo