ftool_test (version 0.0)
You can also look at:
#! /usr/bin/ksh
###########################################################################
#
#
# SYNTAX: ftool_test tool code caller level stdout stderr [filtered]
#
# where tool= the name of the FTOOL which was just run
# code= the exit code returned by the FTOOL
# caller= the name of the routine which called the FTOOL
# level= the level of the error to be generated on failure
# stdout= the name of a file containing the statdard output from
# the FTOOL
# stderr= the name of a file containing the statdard error
# output from the FTOOL
# filtered= stderr with acceptable errors removed
#
#
#
#
# DESCRIPTION: a generic post-FTOOL error checking and cleanup routine
#
# VERSION: 0.0
#
# HISTORY:
#
##############################################################################
#DEBUG=1
tool=$1
code=$2
caller=$3
level=$4
stdout=$5
stderr=$6
filt=$7
####################
# debugguing output
####################
if [ -n "$DEBUG" ]; then
echo ${0##*/}: tool=$tool
echo ${0##*/}: code=$code
echo ${0##*/}: caller=$caller
echo ${0##*/}: level=$level
echo ${0##*/}: stdout=$stdout
echo ${0##*/}: stderr=$stderr
echo ${0##*/}: filt=$filt
fi
##########################
# log the standard output
##########################
outlines=0
if [ -r "$stdout" ]; then
outlines=$(wc -l <$stdout)
fi
if [ $outlines -gt 0 ]; then
################################
# there is some standard output
################################
$UTIL/log_entry "Standard Output From FTOOL ${tool}:"
$UTIL/file_to_log $stdout
fi
#######################################################
# check the number of words in the standard error log
#######################################################
errorlines=0
if [ -r "$stderr" ]; then
errorlines=$(wc -w <$stderr)
fi
filteredlines=$errorlines
if [ -r "$filt" ]; then
filteredlines=$(wc -w <$filt)
fi
####################
# debugguing output
####################
if [ -n "$DEBUG" ]; then
echo ${0##*/}: errorlines=$errorlines
echo ${0##*/}: filteredlines=$filteredlines
fi
###############################
# throw an exception if needed
###############################
if [ $filteredlines -gt 0 -o $code -ne 0 ]; then
$UTIL/exception $caller $level "Error from ${tool}. Exit code=${code}"
fi
################################
# dump stderr if not empty
###############################
if [ $errorlines -gt 0 ]; then
$UTIL/log_entry "Standard Error Output from FTOOL ${tool}"
$UTIL/file_to_log $stderr
fi
################################################
# dump par file to log if there was an error
################################################
if [ $filteredlines -gt 0 -o $code -ne 0 ]; then
if [ -r "${tool}.par" ]; then
$UTIL/log_entry "Par file from FTOOL ${tool}"
$UTIL/file_to_log ${tool}.par
fi
fi
##########################################
# remove logs and par file if they exist
##########################################
if [ -a "${tool}.par" ]; then
rm -f ${tool}.par
fi
if [ -a "$stderr" ]; then
rm -f $stderr
fi
if [ -a "$stdout" ]; then
rm -f $stdout
fi
if [ -a "$filt" ]; then
rm -f $filt
fi
exit $code