Cover V04, I02
Article
Listing 1

mar95.tar


Listing 1: badgrp Script

#!/bin/sh
#
#    badgrp
#
#    Find /etc/passwd entries missing group entries in /etc/group
#
#    Copyright 1994, Lawrence S Reznick -- 94Oct19

PWFILE=/tmp/pw.$$
GRPFILE=/tmp/gp.$$

trap "rm -f $PWFILE $GRPFILE" 1 2 3 15

#
#    If NIS is running, use its maps
#

if ypwhich >/dev/null 2>&1
then
ypcat passwd >$PWFILE
ypcat group >$GRPFILE
else
cat /etc/passwd >$PWFILE
cat /etc/group >$GRPFILE
fi

#
#    Extract a unique list of active accounts' gids
#

for grp in `cut -d: -f4 $PWFILE | sort -nu`
do
grpfmt=`echo :"$grp":`             # Avoid partial matches
match=`egrep $grpfmt $GRPFILE`

test -n "$match" ||
echo Group $grp not in group list, affecting users: \
`egrep $grpfmt $PWFILE | cut -d: -f1`
done

rm -f $PWFILE $GRPFILE