# SccsId[] = "%W% (USL function) %G%"
CPDN_name="CP_DEV_NULL_EXIT_ERR_NOMAIL"
if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
[ ."`set|egrep '^$CPDN_name\(\)\{$'`" != . ] && CPDN_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 '/^'$CPDN_name'[=\(]?/'`" != . ] && CPDN_loaded=1
else # Linux
[ ."`typeset -F|awk '/^'$CPDN_name'[=\(]?/'`" != . ] && CPDN_loaded=1
fi
fi
if [ 0${CPDN_loaded} -eq 0 ]; then
#----------------------------------------------------------------------#
CP_DEV_NULL_EXIT_ERR_NOMAIL() # Function documentation 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 [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi
. $SHLIB/exit.sh
#------------------------------------------------------------#
# If the following variables are not set, use these defaults.#
#------------------------------------------------------------#
: ${script_name:=`basename $0`}
: ${name_root:=`echo $script_name|$AWK '{sub(/^\.+/,"");sub(/\..*/,"");print}'`}
: ${logger_p="user.err"}
: ${logger_t="$LOGNAME[$$]"}
: ${verbose:=0}
: ${sp:=" "}
: ${dashes:="------------------------------------------------------"}
: ${tmp:=/var/tmp}
if [ ."$log" = . ]; then
log=$name_root.log
[ ."$teelog" = . ] && teelog="cat"
fi
CPDN_ID="$script_name($CPDN_name)"
#--------------------------------------------------------------------#
# Process function options and arguments #
# -------------------------------------- #
# We use while-loop instead of getopts because -p (logger priority) #
# option and -t (logger tag option) may or may not have an optarg #
# (the user may just want the defaults). #
#--------------------------------------------------------------------#
CPDN_options="lptv"
CPDN_opt_l=0
CPDN_opt_p=0
CPDN_opt_t=0
CPDN_opt_v=0
CPDN_pri="$logger_p" # $logger_p and $logger_t are assigned defaults
CPDN_tag="$logger_t" # within library defaults.sh.
CPDN_opts=""
CPDN_args=""
while [ ."$1" != . ]
do
#-------------------------------------------------------------#
# If we have an option list (e.g. "-xyz") change that list to #
# individual "-x -y -z" options. Else, just pass the option #
# along. #
#-------------------------------------------------------------#
CPDN_n=`expr "$1". : '-.*'`
if [ $CPDN_n -gt 0 ]; then
if [ $CPDN_n -eq 2 ]; then
CPDN_optargs="$1"
else
CPDN_optargs=`echo "$1"|sed 's/[a-zA-Z]/-& /g;s/--*/-/'`
fi
for CPDN_optarg in $CPDN_optargs
do
case $CPDN_optarg in
-l ) CPDN_opt_l=1
. $SHLIB/write_err_to_syslogs.sh
;;
-p ) if [ $CPDN_opt_l -eq 1 -a $CPDN_opt_p -eq 0 ]; then
CPDN_opt_p=1
if [ -`expr "$2" : '\(\-\)['$CPDN_options']'` != "--" ]; then
CPDN_pri="$2"
shift
fi
else
CPDN_opts="$CPDN_opts $CPDN_optarg"
fi
;;
-t ) if [ $CPDN_opt_l -eq 1 -a $CPDN_opt_t -eq 0 ]; then
CPDN_opt_t=1
CPDN_tag="$2"
if [ -`expr "$2" : '\(\-\)['$CPDN_options']'` != "--" ]; then
CPDN_tag="$2"
shift
fi
else
CPDN_opts="$CPDN_opts $CPDN_optarg"
fi
;;
-v ) CPDN_opt_v=1
;;
esac
done # for CPDN_optarg in $CPDN_optargs
else
[ ."$CPDN_args" != . ] \
&& CPDN_args="$CPDN_args|$1" \
|| CPDN_args="$1"
fi
shift
done # while [ ."$1" != . ]
CPDN_opts=`expr "$CPDN_opts" : ' *\(.*\)'` # Strip leading blanks
CPDN_args=`expr "$CPDN_args" : '|*\(.*\)'` # Strip leading stiles
#----------------------------------------------------------------#
# If we have sufficient arguments, then attempt our cp command. #
#----------------------------------------------------------------#
CPDN_status=0
CPDN_cmd="cp $CPDN_opts /dev/null"
if [ ."$CPDN_args" != . ]; then
echo "$CPDN_args"|awk -F\| '{for (i=1;i<=NF;i++) print $i}' \
| while read CPDN_file
do
[ $verbose -eq 1 -o $CPDN_opt_v -eq 1 ] \
&& echo "`date '+%Y-%m-%d %T'` $CPDN_cmd \"$CPDN_file\"" \
| $teelog
CPDN_stderr=`$CPDN_cmd "$CPDN_file" 2>&1`
CPDN_status=$?
[ $CPDN_status -eq 0 ] && continue
#-----------------------------------------#
# Reaching here means something is amiss. #
#-----------------------------------------#
CPDN_m1="'$CPDN_cmd \"$CPDN_file\"'"
CPDN_m2="ERROR=$CPDN_stderr."
CPDN_m3="$script_name terminated."
CPDN_m4=`ls -al "$CPDN_file"|sed "s/^/$sp/"`
echo "`date '+%Y-%m-%d %T'` FATAL ERROR: $CPDN_ID" 1>&2
echo "${sp}$CPDN_m1" 1>&2
echo "${sp}$CPDN_m2" 1>&2
echo "${sp}$CPDN_m3 File list (in any) follows:" 1>&2
echo "${sp}$dashes" 1>&2
echo "$CPDN_m4" 1>&2
if [ $CPDN_opt_l -eq 1 ]; then # Logger option? (1 = yes)
WRITE_ERR_TO_SYSLOGS -p "$CPDN_pri" -t "$CPDN_tag" \
"ABORT: $CPDN_ID $CPDN_m1 $CPDN_m2 $CPDN_m3"
fi
EXIT 1
done # while read CPDN_file
return 0
fi # if [ ."$CPDN_args" != . ]; then
#--------------------------------------------------------------------#
# Reaching this point means we have an insufficient arguments error. #
#--------------------------------------------------------------------#
CPDN_m1="Insufficient args."
CPDN_m2="$script_name terminated."
echo "`date '+%Y-%m-%d %T'` FATAL ERROR (Function): $CPDN_ID" 1>&2
echo "${sp}$CPDN_m1\n" 1>&2
echo "${sp}Usage: $CPDN_name -l -p priority -t tag -v" 1>&2
echo "${sp} fileid [...]\n" 1>&2
echo "${sp} -l = Notify via logger command" 1>&2
echo "${sp} (default is false)" 1>&2
echo "${sp} -p = Logger priority string" 1>&2
echo "${sp} (default is 'user.err')" 1>&2
echo "${sp} -t = Logger tag string" 1>&2
echo "${sp} (default is '$LOGNAME[$$]')" 1>&2
echo "${sp} -v = Verbose" 1>&2
echo "${sp}Option notes: Option (-l) MUST precede -p and -t." 1>&2
echo "${sp}$CPDN_m2" 1>&2
if [ $CPDN_opt_l -eq 1 ]; then # Logger option? (1 = yes)
WRITE_ERR_TO_SYSLOGS -p "$CPDN_pri" -t "$CPDN_tag" \
"ABORT: $CPDN_ID $CPDN_m1 $CPDN_m2"
fi
EXIT 1
} # "CPDN_" prefix identifies this function's local variables.
fi
#======================================================================#
# D O C U M E N T A T I O N #
#======================================================================#
# #
# Author: Bob Orlando (Bob@OrlandoKuntao.com) #
# #
# Date: December 14, 1996 #
# #
# Program ID: cp_dev_null_exit_err_nomail.sh #
# #
# Usage: CP_DEV_NULL_EXIT_ERR_NOMAIL -l -p priority -t tag -v \ #
# fileid ... #
# #
# -l = Notify via logger command #
# (default is false) #
# -p = Logger priority string #
# (default is "user.err") #
# -t = Logger tag string #
# (default is "$LOGNAME[$$]") #
# -v = Verbose #
# #
# Option notes: Option (-l) MUST precede other options. #
# 'UNIX command options' MUST follow #
# function options. If command option #
# is -l, -p, or -t, and you've specified #
# function option -l, then you must also #
# supply both function options, -p and -t. #
# #
# Purpose: Copy /dev/null to one or more files with error #
# checking and reporting via stderr and logger, and #
# exiting on error. #
# #
# Description: This function adds no new functionality to the UNIX #
# cp command beyond the ability to copy /dev/null to #
# multiple files while providing automatic notification #
# and logging before exiting on error. Unlike its sister #
# function, CP_DEV_NULL_EXIT_ERR, notification here is #
# via an echo to stderr (not via EMAIL_MSG library #
# function). Optionally (-l), the user may have the #
# error logged in syslogs (/var/adm/messages) via the #
# logger command. Logger -p and -t options and option #
# arguments also may be be passed (both have defaults if #
# omitted). #
# #
# Globals: No global variables assigned from this function. #
# "CPDN_" prefix identifies local function variables. #
# #
# Calls: EXIT library function. (DOES NOT use EMAIL_MSG #
# library function for error reporting/notification.) #
# Optionally, WRITE_ERR_TO_SYSLOGS is also called. #
# #
# Exit_status: Exits with failure (1) on error. This is because #
# any error copying /dev/null to a file is a potential #
# show stopper (indicating, possibly, a filesystem #
# error). Else, returns 0. #
# #
# Notes: .................................................... #
# .................................................... #
# #
# Modified: 2004-04-02 Bob Orlando #
# v1.16 * Expand $AWK testing and assignment. #
# #
# 2004-03-03 Bob Orlando #
# v1.15 * Change set|egrep|awk to just set|egrep. #
# #
#----------------------------------------------------------------------#
|