cdesktopenv/cde/admin/BuildTools/tog/extract_msg

240 lines
5.3 KiB
Bash
Executable File

#!/bin/ksh
#
# extract_msg.ksh
#
########################################################################
#set -x
##########################################################################
#
# Script setup: THIS NEEDS TO BE FIRST
#
SCRIPTS_DIR="`dirname $0`"
if [ "" = "$SCRIPTS_DIR" ]; then
SCRIPTS_DIR=/project/dt/scripts
fi
if [ ! -f $SCRIPTS_DIR/script_setup.ksh ]; then
print -u2 "$PRG: File '$SCRIPTS_DIR/script_setup.ksh' NOT found!"
print -u2 "$PRG: Exiting ..."
exit 1
fi
. $SCRIPTS_DIR/script_setup.ksh
DEBUG="False"
IGNORED_MESSAGE_FILES=""
IGNORED_MESSAGES_INIT="XXXXXXX"
IGNORED_MESSAGES="$IGNORED_MESSAGES_INIT"
LOG_FILE=""
ERROR_FILE=""
MESSAGE_FILES=""
MESSAGES_INIT="XXXXXXX"
MESSAGES="$MESSAGES_INIT"
PROG_NAME="`basename $0`"
usage ()
{
print -u1 "USAGE: $1"
print -u1 "\t{-e | -errorfile} <file>"
print -u1 "\t # Specifies the error file to send errors."
print -u1 "\t[-h | -? | -help]"
print -u1 "\t # Print usage and exit"
print -u1 "\t[{-i | -ignoredmsgfile} <file>]"
print -u1 "\t # Specifies a file containing messages to be"
print -u1 "\t # ignored. Multiple -i flags can be specified."
print -u1 "\t{-l | -logfile} <file>"
print -u1 "\t # Specifies the log file to be extracted from."
print -u1 "\t[{-m | -msgfile} <file>]"
print -u1 "\t # Specifies a file containing messages to be"
print -u1 "\t # extracted. Multiple -m flags can be specified."
print -u1 "\t[messages ...]"
print -u1 "\t # Specifies individual messages to be extraced."
}
#
# Do command-line processing
#
while [ $# -gt 0 ]; do
case $1 in
-debug)
DEBUG="True"
shift 1 ;;
-e | -errorfile)
if [ $# -lt 2 ]; then
print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
do_exit 1
fi
ERROR_FILE=$2
shift 2 ;;
-i | -msgfile)
if [ $# -lt 2 ]; then
print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
do_exit 1
fi
IGNORED_MESSAGE_FILES="$IGNORED_MESSAGE_FILES $2"
shift 2 ;;
-m | -msgfile)
if [ $# -lt 2 ]; then
print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
do_exit 1
fi
MESSAGE_FILES="$MESSAGE_FILES $2"
shift 2 ;;
-l | -logfile)
if [ $# -lt 2 ]; then
print -u2 "$PROG_NAME: $1 option missing value; exiting ..."
do_exit 1
fi
LOG_FILE=$2
shift 2 ;;
-h | -? | -help)
usage $PROG_NAME
do_exit 1 ;;
*)
MESSAGES="$MESSAGES|$1"
shift 1;;
esac
done
if [ ! -z "$ERROR_FILE" ]
then
exec 2>> $ERROR_FILE
fi
#
# Check to make sure that the command-line parameters make sense.
#
if [ -z "$MESSAGE_FILES" ] && [ "$MESSAGES" = "$MESSAGES_INIT" ]
then
print -u2 "$PROG_NAME: No messages or message files have been specified."
print -u2 "$PROG_NAME: exiting ..."
do_exit 1
fi
for f in $IGNORED_MESSAGE_FILES
do
if [ ! -f $f ]
then
print -u2 "$PROG_NAME: Message file \"$f\" does not exist; exiting ..."
do_exit 1
fi
done
for f in $MESSAGE_FILES
do
if [ ! -f $f ]
then
print -u2 "$PROG_NAME: Message file \"$f\" does not exist; exiting ..."
do_exit 1
fi
done
if [ -z "$LOG_FILE" ]
then
print -u2 "$PROG_NAME: Missing argument for log file; exiting ..."
do_exit 1
fi
if [ ! -f $LOG_FILE ]
then
print -u2 "$PROG_NAME: Log file \"$LOG_FILE\" does not exist; exiting ..."
do_exit 1
fi
#
# Determine where to find perl.
#
PERL="/usr/local/bin/perl"
if [ ! -x $PERL ]
then
print -u2 "$PROG_NAME: Can't find perl executable $PERL; exiting ..."
do_exit 1
fi
#
# Collect all the regular expressions from the ignored message files.
#
for f in $IGNORED_MESSAGE_FILES
do
IGNORED_MESSAGES="$IGNORED_MESSAGES`sed -e '1,$s/.*/|&/' $f`"
done
#
# Collect all the regular expressions from the message files.
#
for f in $MESSAGE_FILES
do
MESSAGES="$MESSAGES`sed -e '1,$s/.*/|&/' $f`"
done
if [ "$DEBUG" = "True" ]
then
print -u1 "======= DEBUG DEBUG IGNORED MESSAGES DEBUG DEBUG ========"
print -u1 $IGNORED_MESSAGES
print -u1 "======= DEBUG DEBUG ================ DEBUG DEBUG ========"
print -u1 "======= DEBUG DEBUG MESSAGES DEBUG DEBUG ========"
print -u1 $MESSAGES
print -u1 "======= DEBUG DEBUG ================ DEBUG DEBUG ========"
fi
#
# Build the perl script
#
SCRIPT=/tmp/${PROG_NAME}.$$.pl
if [ "$DEBUG" = "False" ]
then
do_register_temporary_file $SCRIPT
fi
touch $SCRIPT
chmod 755 $SCRIPT
print -u1 "#!$PERL" >> $SCRIPT
print -u1 "LINE: while (<>) {" >> $SCRIPT
IFS="|"
for m in $IGNORED_MESSAGES
do
MESSAGE=`echo $m | sed -e 's?\/?\\\/?g'`
print -u1 "next LINE if /$MESSAGE/;" >> $SCRIPT
done
for m in $MESSAGES
do
MESSAGE=`echo $m | sed -e 's?\/?\\\/?g'`
print -u1 "next LINE if /$MESSAGE/ && print;" >> $SCRIPT
done
IFS=" "
print -u1 "}" >> $SCRIPT
if [ "$DEBUG" = "True" ]
then
print -u1 "======= DEBUG DEBUG SCRIPT DEBUG DEBUG ========"
cat $SCRIPT
print -u1 "======= DEBUG DEBUG ================ DEBUG DEBUG ========"
fi
#
# Use the perl script to extract the desired messages from the log file.
#
if [ "$DEBUG" = "True" ]
then
print -u1 "======= DEBUG DEBUG RUN SCRIPT DEBUG DEBUG ========"
print -u1 cat $LOG_FILE | $SCRIPT
print -u1 "======= DEBUG DEBUG ================ DEBUG DEBUG ========"
fi
cat $LOG_FILE | $SCRIPT
#
# Clean up temporary files and exit
#
do_exit 0