#! /bin/sh
#
# $Header: cleanup,v 3.5 87/06/22 14:40:45 kjmcdonell Beta $
#
#  Cleanup when an iterative test terminates
#
log=Results/log
while ( test $# -ge 1 )
do
    opt=$1
    shift
    case $opt
    in

    -a)	: abort
	echo '' >>$log
	echo '**************************' >>$log
	echo '* Benchmark Aborted .... *' >>$log
	echo '**************************' >>$log
	echo 'Benchmark Aborted ....'
	echo  ; sleep 2 ; echo  ; sleep 2 ; echo 
	echo "" >>$log
	echo " " `who | wc -l` "interactive users." >>$log
	echo "" >>$log
	date=`date`
	echo "End Benchmark Run ($date) ...." >>$log
	echo "End Benchmark Run ($date) ...."
	;;


    -f)	: filesystem throughput
	awk -f fs.awk <$1 >>$log
	rm -f $1
	shift
	;;
    
    -i)	: report last iteration
	echo "Terminated during iteration $1" >>$log
	shift
	;;

    -l) : logfile
	log=$1
	shift
	;;
    
    -r) : reason for failure
	echo $1
	echo $1 >>$log
	shift
	;;

    -m)	: mem throughput tests
	awk -f mem.awk <$1 >>$log
	rm -f $1
	shift
	;;

    -t)	: timing with /bin/time
	awk -f time.awk <$1 >>$log
	rm -f $1
	shift
	;;

    -w) : work - save information from multi-user test
	worktmp=Tmp/work.tmp
	for m in Tmp/masterlog.*
	do
	    if ( test $m != "Tmp/masterlog.*" )
	    then
		echo ${m}: >>$worktmp
		cat $m >>$worktmp
		echo "" >>$worktmp
		rm -f $m
	    fi
	done
	for u in Tmp/userlog.*
	do
	    if ( test $u != "Tmp/userlog.*" )
	    then
		echo ${u}: >>$worktmp
		cat $u >>$worktmp
		echo "" >>$worktmp
		rm -f $u
	    fi
	done
	PS1=`sh -ic "" 2>&1`
	sed -e "s/\\${PS1}//g" $worktmp | sed -f check.sed >loggederrs
	if ( test -s loggederrs )
	then
	    echo "*************************************" >>$log
	    echo "* Apparent errors from makework ... *" >>$log
	    echo "*************************************" >>$log
	    cat loggederrs >>$log
	fi
        rm -f loggederrs
	cat $worktmp >>${log}.work
	rm -f $worktmp
	;;

    '')	: 'skip it (residual effect of shifts)'
	;;

    *)
	echo "cleanup: bad option ($opt)" >>$log
esac
done
exit
