# SccsId[] = "%W% (USL function) %G%"
VV_name="VERIFY_VARS"
if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
[ ."`set|egrep '^$VV_name\(\)\{$'`" != . ] && VV_loaded=1
else # Korn or Bash shell and function already loaded?
if [ `expr "\`uname -s\`" : "[Ll][Ii][Nn][Uu][Xx]"` -eq 0 ]; then
[ ."`typeset +f|awk '/^'$VV_name'[=\(]?/'`" != . ] && VV_loaded=1
else # Linux
[ ."`typeset -F|awk '/^'$VV_name'[=\(]?/'`" != . ] && VV_loaded=1
fi
fi
if [ 0${VV_loaded} -eq 0 ]; then
#----------------------------------------------------------------------#
VERIFY_VARS() # Function documentation located at bottom. #
#----------------------------------------------------------------------#
{ [ ."${AWK}" = . ] && { { [ -x /usr/bin/nawk ] && AWK=/usr/bin/nawk; } \
|| { [ -x /bin/gawk ] && AWK=/bin/gawk ; } \
|| { [ -x /usr/bin/awk ] && AWK=/usr/bin/awk ; }; }
#------------------------------------------------------------#
# If the following variables are not set, use these defaults.#
#------------------------------------------------------------#
: ${script_name:=`basename $0`}
: ${sp:=" "}
VV_ID="$script_name($VV_name)"
if [ $# -gt 0 ]; then
#-----------------------------------------------------------------#
# The trick here is to run the entire block of code in background #
# (hence the beginning and end parentheses on separate lines). #
# Doing this allows us to use environmental variables (the only #
# ones nawk is capable of seeing) without affecting any that have #
# identical names in foreground which might have the same names. #
# #
VV_errors=`( # Begin background operation.
export $* # Export these dogs so nawk can examine them.
#--------------------------------------------------------------#
# FYI: If you want to sort the variables and eliminate dupes #
# you can do the following: #
# echo $*|awk "{for (n=1;n<=NF;n++) print $n}"| sort | uniq \ #
# | $AWK "BEGIN { p = q = 0 } ... (ommitting the RS = ""). #
#--------------------------------------------------------------#
echo $* | $AWK -v sp="$sp" \
'BEGIN { RS = " "; p = q = 0 } # Initialization
#----------------------------------------------#
# Action section runs through our variables #
# and assigns them to our var[] array. #
#----------------------------------------------#
{ var[++q] = $1 }
#----------------------------------------------#
# This is where we verify variable assignments.#
#----------------------------------------------#
END \
{ err_n = 0
for (p=1; p<=q; p++)
{
sub(/^[\n\r\t ]+/, "",ENVIRON[var[p]])
gsub(/[\n\r\t ]+/," ",ENVIRON[var[p]])
if (ENVIRON[var[p]] == "")
{
print sp"$"var[p]" is unassigned."
err_n++
}
}
exit err_n
}'
) 2>&1` # End of background export and nawk process.
[ $? -eq 0 ] && return 0
# #
#-----------------------------------------------------------------#
fi
#------------------------------------------------------------#
# Reaching this point means that we either have insufficient #
# args or the nawk process uncovered an unassigned variable. #
#------------------------------------------------------------#
if [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi
. $SHLIB/exit.sh # Function dependencies
. $SHLIB/email_msg.sh # Calls $SHLIB/exit.sh
. $SHLIB/write_err_to_syslogs.sh
VV_msg="$script_name terminated."
if [ $# -lt 1 ]; then
VV_errors="Insufficient args!"
VV_m1="Usage: $VV_name var ..."
VV_m2=" NOTE: 'var' MUST NOT have a leading '$'."
EMAIL_MSG "FATAL ERROR (Function): $VV_ID" \
"${sp}$VV_errors" \
"${sp}$VV_m1" \
"${sp}$VV_m2" \
"\n${sp}$VV_msg"
else
EMAIL_MSG "FATAL ERROR: $VV_ID" \
"${sp}$VV_errors" \
"${sp}$VV_msg"
fi
if [ ."${TERM}" = . ]; then
WRITE_ERR_TO_SYSLOGS $syslog_emergency \
"ABORT: $VV_ID $VV_errors $VV_msg"
fi
EXIT 1
} # "VV_" prefix identifies this function's local variables.
fi
#======================================================================#
# D O C U M E N T A T I O N #
#======================================================================#
# #
# Author: Bob Orlando #
# #
# Date: October 30, 1997 #
# #
# Program ID: verify_vars.sh #
# #
# Usage: VERIFY_VARS var ... #
# #
# Usually a list, 'var' is a critical variable name #
# that we check to ensure it is assigned. #
# #
# Purpose: Library function to verify the assignment of critical #
# process variables. Because they are critical to the #
# operation of the process, finding any without #
# values, terminates the process. (All the unassigned #
# variables are reported at that time.) #
# #
# Globals: No global variables are assigned in this function. #
# "VV_" prefix identifies local function variables. #
# #
# Exit_status: Exits with 1 (failure) for severe error (e.g. user #
# supplies an invalid argument) or if any of the #
# variables are unassigned. Otherwise, returns 0 #
# (success). #
# #
# Calls: EMAIL_MSG and WRITE_ERR_TO_SYSLOGS library functions. #
# #
# Notes: .................................................... #
# .................................................... #
# #
# Modified: 2004-04-02 Bob Orlando #
# v1.10 * Expand $AWK testing and assignment. #
# #
# 2004-03-03 Bob Orlando #
# v1.9 * Change set|egrep|awk to just set|egrep. #
# #
#----------------------------------------------------------------------#
|