#!/bin/sh
PREFIX=$(expr $0 : "\(/.*\)/bin/$(basename $0)\$") || exit 1
if [ -r $PREFIX/etc/utcount.conf ]; then
. $PREFIX/etc/utcount.conf
else
exit 1
fi
TMPDIR=$user_tmpdir
export TMPDIR
tmpfile=`mktemp -q -u -t count` || exit 1
cleanup ()
{
rm -f $tmpfile.?
}
trap : 1
trap : 2
trap : 15
set -T
trap "cleanup; exit" 1 2 15
bindir=$PREFIX/bin
count_eval=""
for progname in $user_list
do
if [ $count_eval ] ; then
count_eval="$count_eval ; $bindir/count_$progname"
else
count_eval="$bindir/count_$progname"
fi
done
count_num=0
touch $tmpfile.$count_num
while [ ! ]
do
if ! ps $PPID >/dev/null 2>&1
then
echo "Parent process died. Cleanup and exit." >&2
break
fi
count_old=$count_num
test $count_num -eq 1
count_num=$?
eval $count_eval | tee $tmpfile.$count_num \
| diff -b -u $tmpfile.$count_old - \
| grep "^[+-] [a-z]" | sort -r
sleep $user_sleeptime
done
cleanup
syntax highlighted by Code2HTML, v. 0.9.1