Sponsored Content
Full Discussion: Debug needed
Top Forums Shell Programming and Scripting Debug needed Post 302521739 by baraghun on Thursday 12th of May 2011 06:16:23 AM
Old 05-12-2011
Debug needed

Here is a script built to pull out the error report. But this is ending up with certain errors.

Code:
#!/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:

Code:
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

 

9 More Discussions You Might Find Interesting

1. Programming

how to debug

i am new to solaris i have one module which contain certain header files and sub modules i want ot execute the module and c what the values are beeing assigned to variables is makefile only solution for this is there any editor to help it,so that i can c the flow of the program and also... (1 Reply)
Discussion started by: ramneek
1 Replies

2. Shell Programming and Scripting

debug this script

echo "input time in hhmmss" read $st h=`echo $st | cut -c1-2` min=`echo $st | cut -c3-4` s=`echo $st | cut -c5-6` echo "input time in hhmmss" read $end h1=`echo $end | cut -c1-2` min1=`echo $end | cut -c3-4` s1=`echo $end | cut -c5-6` x= `expr $h /* 60 + $min` y= `expr $h1 /* 60 +... (8 Replies)
Discussion started by: abhishek27
8 Replies

3. OS X (Apple)

How to debug signals

Hi, In our program, we are using SIGTERM and i tired to put break point in this function. But my debuger is unable to brake at that point. I am working on Mac X and using XCode. Thanks (0 Replies)
Discussion started by: Saurabh78
0 Replies

4. Programming

Can we debug Signals

Hi, In our program, we are using SIGTERM and i tired to put break point in this function. But my debuger is unable to brake at that point. I am working on Mac X and using XCode. Thanks (1 Reply)
Discussion started by: Saurabh78
1 Replies

5. Shell Programming and Scripting

Debug mode

When I run a lengthy script in debug mode i need to capture all the steps which are executed. e.g ksh -x script.ksh + test -f /proc/mounts + /bin/ls -l /proc/21326/exe + is=ksh + test ksh = ksh + test -s /etc/ksh.kshrc + . /etc/ksh.kshrc + trap 1 2 3 + who am i + awk {print $1} +... (2 Replies)
Discussion started by: zooby
2 Replies

6. Solaris

How to debug .so file??

Hi All, I have a question on debugging the .so file. When I am running makefile I am getting a .so file and we are using that .so file for executing our code.But I want to know 1.Can I use dbx or gdb to debug a .so file? 2.How can i generate .out file so that i can use that in dbx or gdb... (1 Reply)
Discussion started by: s.sen1213
1 Replies

7. Shell Programming and Scripting

If - then -else debug please

Can you help please ? ./get_df.sh: syntax error at line 13 : `then' unexpected #!/bin/ksh while : do PER=`df -h /DATA/ | nawk '{if (NR != 1) { sub (/%/,""); print $(NF-1)}}'` if then if] then mailx -s "FS over 90 per" me@company.com touch... (2 Replies)
Discussion started by: drbiloukos
2 Replies

8. OS X (Apple)

Debug help

Hello, I was looking at kernel log's and found some parts what was "interesting" I previously started looking what has been going on in my computer because I had hacker attacks on my machine. Installed Avira & Little Snitch - softwares Previously my computer opened few folders what I have... (1 Reply)
Discussion started by: Scourge-
1 Replies

9. Ubuntu

Debug script

How can I debug this script? I want to know what it is doing or not doing? #!/bin/bash # # if ; then # Do the thing you want before suspend here echo "we are suspending." > /tmp/systemd_suspend_test.txt elif ; then # Do the thing you want after resume here echo "and we are... (21 Replies)
Discussion started by: drew77
21 Replies
All times are GMT -4. The time now is 11:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy