Here is a script built to pull out the error report. But this is ending up with certain errors.
#!/bin/bash
# Refining Error Text from XML Log
#
##***********************************************************************************
## ********** FUNCTION USAGE *********** ##
##***********************************************************************************
##
# Script name without path
BASENAME=${0##*/}
#Default Config & Log Path
HOME=/home/user1/
#
#
#
#The INFILE is going to use during the SSH
#liveFilePattern="${HOME}/conf/app.properties.live.txt"
#archFilePattern="${HOME}/conf/app.properties.archive.txt"
#####################################################################
############### VARIABLE PARAMETERS ###############
#####################################################################
USER=`who -m | awk '{print $1}'`
DATE=`date +%y%m%d%`
LOG_NAME_DATE=`date +%y%m%d% -%H%M%S`
ERROR_LOG_DIR=$HOME/ErrorLog/
CLI_LOG_DIR=$ERROR_LOG_DIR/Client/
CLI_LOG=$CLI_LOG_DIR/Client-Log-${USER}.${LOG_NAME_DATE}
SER_LOG_DIR=$ERROR_LOG_DIR/Server
SER_LOG=$SER_LOG_DIR/Server-Log-${USER}.${LOG_NAME_DATE}
OUT_FILE=$ERROR_LOG_DIR/$SERVICE_NAME_${DATE}
LOG_DIR="/logs/ApplID/log"
ARC_DATE=" "
ProviderError="Error"
CUR_FILE_LIST=`ls -ltr | grep -i ${Service_NAME} | grep -v *.gz`
ARC_FILE_LIST=`ls -ltr | grep -i ${ARC_DATE} | grep -i ${Service_NAME}`
#Searching Provider Error Code File
ClientErr="${HOME}/conf/errDef_client" ### Client Error Code & Defintion ###
ServerErr="${HOME}/conf/errDef_server" ### Server Error Code & Defintion ###
######################################################################
################## USAGE ##################
######################################################################
if [ $# != 2 ] then
usage() {
echo
echo "USAGE:"
echo " $BASENAME [ -l <LOG_FILE> | -a <DATE:YYYY-MM-DD> <OLD_LOG_FILE> ]" <-c | -s> "
echo
echo " <-l> = Enter the vaild service file Name.Example: dp_subscribermanagementservice.
This switch is used to search in current dated file.
<-a> = Enter the valid Service File Name.Example: dp_subscribermanagementservice
This switch is used to search in archived file list. When using -a switch even date should
be passed as an argument before File Argument. Viz -a [yyyy-mm-dd] [File_Name].
<-c> = Checking for Client Specific error Text.
<-s> = Checking for Server Specific error Text."
if [ "$2" != 0 ]|| [ "$1" != 0 ] then
echo
echo " Check USAGE for correct Parameters "
fi
exit 1
}
function searchFile() {
#checking for service name in Service LOG Directory whether its Current Log or Archived(Live/Archive)
#
case $1 in
-L | -l)
cd ${LOG_DIR}
stat=$?
if [ $stat -ne 1 ]
then
echo " "
echo "Plugging to Service Log Directory: << `pwd` >> is SUCCESSFULL"
echo " "
fi
CurrentLogList=$CUR_FILE_LIST
status=$?
if [ $status -ne 1 ]
then
echo " "
echo "***Found Current Logs ***"
while read providerErrorCode
do
n="1 2 3 4 5"
logFile="${CUR_FILE_LIST}"
for i in $n
do
echo "**********************************************************"
echo "Isolating all Error Transaction"
echo " "
searchString=egrep -i "$ProviderError" "${logFile}$i" | cut -d'|' -f2,16,17 | sed -e 's/|REQUEST_MESSAGE=/<REQUEST>/g' -e 's/|RESPONSE_MESSAGE=/<\/REQUEST><RESPONSE>/g'
-e 's/Envelope>$/&<\/RESPONSE>/g' -e 's/.]$/&<\/RESPONSE>/g'> $Error_LOG/$OUT_FILE
echo "**********************************************************"
status=$?
if [ $status -ne 1 ]
then
echo "Isolation Completed"
else
echo "No Errors found, needs to be Isolated"
fi
done
done < "${myString}"
else
echo "Either FILE is INVALID or DOES NOT EXISTS"
fi
;;
-A | -a)
cd ${LOG_DIR}
stat=$?
if [ $stat -ne 1 ]
then
echo " "
echo "Plugging to Service Log Directory: << `pwd` >> is SUCCESSFULL"
echo " "
fi
CurrentLogList=$CUR_FILE_LIST
status=$?
if [ $status -ne 1 ]
then
echo " "
echo "***Found Archived Logs ***"
while read providerErrorCode
do
n="1 2 3 4 5"
logFile="${ARC_FILE_LIST}"
for i in $n
do
echo "**********************************************************"
echo "Isolating all Error Transaction \n"
echo "Wait for few Minutes"
searchString=`gzegrep -i "$ProviderError" "${logFile}$i" | cut -d'|' -f2,16,17 | sed -e 's/|REQUEST_MESSAGE=/<REQUEST>/g' -e 's/|RESPONSE_MESSAGE=/<\/REQUEST><RESPONSE>
/g' -e 's/Envelope>$/&<\/RESPONSE>/g' -e 's/.]$/&<\/RESPONSE>/g'> $Error_LOG/$OUT_FILE &2>/dev/null
echo "**********************************************************"
status=$?
if [ $status -ne 1 ]
then
echo "Isolation Completed"
else
echo "No Errors found, needs to be Isolated"
fi
done
done < "${ProviderError}"
else
echo "Either FILE is INVALID or DOES NOT EXISTS"
fi
;;
*) usage
;;
esac
}
searchFile
function refineFileType() {
## Refining the Errot Type from the Isolated Error Log
Case $2 in
-C | -c)
REF_FILE=$Error_LOG/$OUT_FILE
if [ -e $REF_FILE ] && [ -r $REF_FILE] then
printf " Wait a moment Untill I get you Client Specific Error "
reFineLog=`egrep -i $ClientErr $REF_FILE | sed -e 's/>\(<[^:]*:providerErrorCode\)/> \1/g' -e 's/\(<\/[^:]*:providerErrorCode>\)</\1 </g' 's/>\
(<[^:]*:providerErrorText\)/> \1/g' -e 's/\(<\/[^:]*:providerErrorText>\)</\1 </g' > $CLI_LOG`
if [ $? != 0] then
Printf " There are No Client Related Logs "
else
Printf " Getting you the Client Error Text for the $SERVICE_NAME
errorText=`/usr/xpg4/bin/awk -F' [<>]' '{print $1 $2}' $CLI_LOG | awk -F'>' '{print $2}' | cut -d'<' -f1 | sort -nr | uniq -c > Client_Table_$
Date`
awk 'BEGIN {print "======================================================="
print " Error Code | Count | Error Description "
print "======================================================="}
/:/&&/^$ClientErr/ {print substr($1,1,9), substr($1,10,4),$2;next}
/^$ClientErr/ {print substr($1,1,9), substr($1,10,4),substr($1,14)}
END{print "========================================================"}'OFS="|" Client_Table_$Date
Printf " "
Printf " Error Start Time : `cut -d'|' -f1 Client_Table_$Date sort -rn | head -n 1` "
Printf " Error Last Recorded Time : `cut -d'|' -f1 Client_Table_$Date | sort -rn | tail -f1` "
fi
fi
-S | -s)
REF_FILE=$Error_LOG/$OUT_FILE
if [ -e $REF_FILE ] && [ -r $REF_FILE] then
printf " Wait a moment Untill I get you Server Specific Error "
reFineLog=`egrep -i $ServerErr $REF_FILE | sed -e 's/>\(<[^:]*:providerErrorCode\)/> \1/g' -e 's/\(<\/[^:]*:providerErrorCode>\)</\1 </g' 's/>\
(<[^:]*:providerErrorText\)/> \1/g' -e 's/\(<\/[^:]*:providerErrorText>\)</\1 </g' > $SER_LOG`
if [ $? != 0] then
Printf " There are No Server Related Logs "
else
Printf " Getting you the Server Error Text for the $SERVICE_NAME
errorText=`/usr/xpg4/bin/awk -F' [<>]' '{print $1 $2}' $SER_LOG | awk -F'>' '{print $2}' | cut -d'<' -f1 | sort -nr | uniq -c > Server_Table_$
Date`
awk 'BEGIN {print "======================================================="
print " Error Code | Count | Error Description "
print "======================================================="}
/:/&&/^$ServerErr/ {print substr($1,1,9), substr($1,10,4),$2;next}
/^$ServerErr/ {print substr($1,1,9), substr($1,10,4),substr($1,14)}
END{print "========================================================"}' OFS="|" Server_Table_$Date
Printf " "
Printf " Error Start Time : `cut -d'|' -f1 Server_Table_$Date sort -rn | head -n 1` "
Printf " Error Last Recorded Time : `cut -d'|' -f1 Server_Table_$Date | sort -rn | tail -f1` "
fi
*)
usage
;;
esac
}
refineFileType
exit
The error what im getting is:
Usage: grep -hblcnsviw pattern file . . .
Usage: grep -hblcnsviw pattern file . . .
Usage: grep -hblcnsviw pattern file . . .
errorText.sh: line 214: unexpected EOF while looking for matching ``'
errorText.sh: line 224: syntax error: unexpected end of file