stool_test (version 0.0)

You can also look at:
#! /usr/bin/ksh

###########################################################################
#
# 
# SYNTAX:  stools_test tool code caller level stdout stderr
#          
#          where tool= the name of the STOOL which was just run
#                code= the exit code returned by the STOOL
#                caller= the name of the routine which called the STOOL
#                level=  the level of the error to be generated on failure
#                stdout= the name of a file containing the statdard output from
#                        the STOOL
#                stderr= the name of a file containing the statdard error
#                        output from the STOOL
#
#
#
# DESCRIPTION:  a generic post-STOOL error checking and cleanup routine
#
# VERSION: 0.0
#
# HISTORY:
#
##############################################################################
#DEBUG=1

tool=$1
code=$2
caller=$3
level=$4
stdout=$5
stderr=$6

if [ -n "$DEBUG" ]; then
     echo ${0##*/} tool=$tool
     echo ${0##*/} code=$code
     echo ${0##*/} caller=$caller
     echo ${0##*/} level=$level
     echo ${0##*/} stdout=$toostdout
     echo ${0##*/} stderr=$stderr
fi


##########################
# log the standard output
##########################
if [ -r "$stdout" ]; then
     outlines=$(wc -l <$stdout)
else
     outlines=0
fi
if [ $outlines -gt 0 ]; then
     ################################
     # there is some standard output
     ################################
     $UTIL/log_entry "Standard Output From STOOL ${tool}:"
     $UTIL/file_to_log $stdout

     
fi

#######################################################
# check the number of lines in the standard error log
#######################################################
if [ -a "$stderr" ]; then
     errorlines=$(wc -l <$stderr)
else
     errorlines=0
fi

if [ $errorlines -gt 0 -o $code -ne 0 ]; then
     #########################
     # there was an error
     ######################### 
     $UTIL/exception $caller $level "Error from ${tool}. Exit code=${code}"
     if [ $errorlines -gt 0 ]; then
	  $UTIL/log_entry "Standard Error Output from STOOL ${tool}"
	  $UTIL/file_to_log $stderr
     fi

fi

#############################
# remove logs if they exist
##############################
if [ -a "$stdout" ]; then
     rm -f $stdout
fi

if [ -a "$stderr" ]; then
     rm -f $stderr
fi




exit $code