#!/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2019 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# sccsid = "@(#)63   1.3   src/rsct/ffdc/bin/fcsysparse.sh, ffdc, rsct_rady, rady2035a 11/12/15 16:42:52"
# =============================================================================
# Module Name:	fcsysparse.sh
#
# Component:	ffdc
#
# Description:	Extracts entries from a Syslog configuration file (ex:
#		/etc/syslog.conf) that record messages to normal files, and
#		maps these normal files to the selector codes that would be
#		used in an FFDC Failure Identifier for Syslog entries.  This
#		is accomplished by first stripping and compressing the Syslog
#		configuration file using "sed", then parsing that result with
#		an "awk" script to identify all selectors making use of files.
#		These files are then examined, and any non-normal files are
#		discarded.
#
# Usage:	fcsysparse.sh [ <pattern> ] <Syslog_configuration_file_name>
#
#		where:	<pattern>	(optional) If specified, indicates
#					a pattern to find in the Syslog
#					configuration file.  If this is
#					specified, only the entry with this
#					<pattren> will be displayed if it sends
#					messages to a normal text file..  If not
#					specified, any entries that write
#					messages to normal text files will be
#					displayed.
#
# Input:	Input is read from $1, which is expected to be a valid Syslog
#		configuration file.  Input is not accepted from standard input.
#
# Output:	One or more lines in the following format:
#			<base_64_code>\t<file_name>
#		where:
#			<base_64_code>	A 6-digit base-64 encoding that
#					indicates the facility and the priority
#					associated with a specific log file
#			<log_file>	Was obtained from the action field of
#					the Syslog configuration file entry for
#					this selector
#		Output is generated only for "normal" files (or non-existent
#		files, which are assumed to be normal files waiting to be
#		created).
#
# Exit Status:	0	Normal completion
# =============================================================================
# Set path to known value
PATH=/opt/rsct/bin:/usr/xpg4/bin:/usr/bin:/usr/sbin:/bin
export PATH
# Script variables
SEDSCRIPT1="./fcstrip.sed"
SEDSCRIPT2="./fcjoin.sed"
AWKSCRIPT="./fcparse.awk"
# Obtain the list of selectors from the Syslog configuration file that write
# messages to files only.
if test $# -gt 1
then
	PATTERN=$1
	shift
else
	PATTERN=""
fi
LIST=$(sed -f $SEDSCRIPT1 $1 | sed -f $SEDSCRIPT2 | awk -f $AWKSCRIPT)
I=0
# Scan the list of logfiles and remove those that do not reference normal
# files (entries that reference non-existent files are considered to be
# referencing normal files)
for COMPONENT in $LIST
do
	if test $I -eq 0
	then
		SELECTOR=$COMPONENT
		I=1
	else
		if test -n "$PATTERN"
		then
			if test "$SELECTOR" != "$PATTERN"
			then
				I=0
				continue
			fi
		fi
		LOGFILE=$COMPONENT
		if test ! -e $LOGFILE
		then
			# Output format is "selector<tab>logfile"
#DEBUG			echo "$SELECTOR	$LOGFILE [non-existent]"
			echo "$SELECTOR	$LOGFILE"
		else
			if test -f $LOGFILE
			then
				# Output format is "selector<tab>logfile"
#DEBUG				echo "$SELECTOR	$LOGFILE [normal]"
				echo "$SELECTOR	$LOGFILE"
#DEBUG			else
#DEBUG				echo "$SELECTOR $LOGFILE [unusable]"
			fi
		fi
		I=0
	fi
done
exit 0