: #	@(#)ppsquish	1.1	lastrites log condenser
# ppshrinklog:
#	Condense the ppurge status file for the given user.  Only the
#	begin and done records for ppurge are left.
# Author:  Larry Bamford, AO, OAT, STD, SEB, ETC, 5/27/92

STATUSFILE=${ADM:-/adm}/lastrites export STATUSFILE
PATH=/bin:/etc:/usr/bin:/adm export PATH	# for security
CMD=`basename $0`

USAGE="
Usage:  $CMD Ousername

Condense the ppurge status file ($STATUSFILE) for the given user.
Only the begin and done records for ppurge are left.
"

# Process command line.
set -- `getopt h\? $*`
if test $? != 0
then echo "$USAGE" 1>&2; exit 2
fi
for i in $*
do case $i in
	-[h\?])	echo "$USAGE"; exit 0;;
	--)	shift; break;;
	esac
done
if test $# -ne 1
then	echo "$CMD:  no account name given" 1>&2
	echo "$USAGE" 1>&2; exit 1
fi
OUSER=$1

# must be root to run this program
ID=`id`
TMP=`expr "$ID" : '.*\(uid=0(\)'`
if test -z "$TMP"
then
	echo "$CMD: you must be root or admin to use this program"
	exit 3
fi

# Get to work.
sed "
/^$OUSER|[^|]*|begin ppurge$/p
/^$OUSER|[^|]*|done ppurge$/p
/^$OUSER|[^|]*.*failed!$/p
/^$OUSER|/d
" $STATUSFILE > ${STATUSFILE}.tmp
ln ${STATUSFILE}.tmp $STATUSFILE
rm ${STATUSFILE}.tmp
