#!/bin/sh
trap "rm -f \$LIBDIR/\$temp; exit 1" 1 2 3 4 5 6 7 8 10 12 13 14 15 16

AWK=gawk

LIBDIR=/local/byname/notes/lib
temp=Atmp$$
SPOOL=$1
cd $SPOOL

find . -name BODY.TEXT -print | $AWK '
{
	++num_files;
	group_name=substr($0,3,length($0)-12);
	     # -12 to remove length of leading "./" and trailing "/BODY.TEXT"
	gsub("/", ".", group_name);
	print group_name;
}

END {
	print "!!Active files: " num_files;
}
' > $LIBDIR/$temp

sort -o $LIBDIR/$temp $LIBDIR/$temp
#This reduces the odds of corruption by another parallel run
if [ -s $LIBDIR/$temp ]
then
	mv $LIBDIR/$temp $LIBDIR/Active
	chmod 0664 $LIBDIR/Active
fi
