Debug needed

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

You should start debugging it step by step yourself. As a start the first errors you get with grep, it seems that there is missing either the pattern or the file. Add a set -x in the previous line of the first grep in your code and check, which of them is incomplete/has a wrong syntax. You can turn off that debugging with set +x .

Why didn't you post those errors in your other post, instead of

Pludi,

Its been a null output in the previous script, Dint see any such kind of errors. But i slightly modified the script and popped up with some errors. I'm seeing the functions are not getting executed properly, instead errors were found.

Zaxxon,

I set the script to run into debug mode, but Im unable to trace the real errors .

Below is the error found.


+ BASENAME=errorText.sh
+ HOME=/home/jg355187/
++ awk '{print $1}'
++ who -m
+ USER=gt266542
++ date +%y%m%d%
+ DATE=110512%
++ date +%y%m%d% -%H%M%S
+ LOG_NAME_DATE=110512%
+ ERROR_LOG_DIR=/home/jg355187//ErrorLog/
+ CLI_LOG_DIR=/home/jg355187//ErrorLog//Client/
+ CLI_LOG=/home/jg355187//ErrorLog//Client//Client-Log-gt266542.110512%
+ SER_LOG_DIR=/home/jg355187//ErrorLog//Server
+ SER_LOG=/home/jg355187//ErrorLog//Server/Server-Log-gt266542.110512%
+ OUT_FILE=/home/jg355187//ErrorLog//110512%
+ LOG_DIR=/logs/45n/production/DATAPOWER/tranlogs/
+ ARC_DATE=' '
+ Service_NAME=' '
+ ProviderError=Error
+ ClientErr=/home/jg355187//conf/errDef_client
+ ServerErr=/home/jg355187//conf/errDef_server
errorText.sh: line 216: unexpected EOF while looking for matching ``'
errorText.sh: line 226: syntax error: unexpected end of file

Having special characters in a multi-line echo in function usage(), you should put in some more echoes and escape them all by surrounding the lines with " in the front and the end:

        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."

Use something like:

...
echo "                 <-c>     = Checking for Client Specific error Text."
...

This as a first step, then check out what is not working next.

This line is correct syntax to start a function:
usage() {

This line (and many more like it) is not correct syntax to start a function.
function searchFile() {

This "if" test is misplaced, syntactically incorrect and upsetting the whole structure of the script.

You probably meant to declare the function "usage" first, then later in the script ....

if [ $# -ne 2 ]
then
        usage
fi

There are more typos in the script, some of which matter (like "Case" instead of "case") and some less important like the spelling of "successful"!

As others suggest, work you way through the script correcting each error. As this strikes me as an edit to a complex script perhaps introduce the changes bit-by-bit and test at every stage.

This does not produce what you think. Even after removing the space character there is an extra % character. Try it?

This might be better:

LOG_NAME_DATE=`date +'%y%m%d-%H%M%S'`

Or even:

LOG_NAME_DATE=`date +'%Y%m%d-%H%M%S'`