Debug needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Debug needed
# 1  
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

# 2  
Old 05-12-2011
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.
# 3  
Old 05-12-2011
Why didn't you post those errors in your other post, instead of
Quote:
Originally Posted by baraghun
Not getting any result for which it has been build
# 4  
Old 05-12-2011
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.

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

# 5  
Old 05-12-2011
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:
Code:
        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:
Code:
...
echo "                 <-c>     = Checking for Client Specific error Text."
...

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

Last edited by zaxxon; 05-12-2011 at 09:47 AM.. Reason: typo and adding a sentence
# 6  
Old 05-12-2011
Code:
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.
Quote:
if [ $# != 2 ] then
usage() {
You probably meant to declare the function "usage" first, then later in the script ....
Code:
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.


Quote:
LOG_NAME_DATE=`date +%y%m%d% -%H%M%S`
This does not produce what you think. Even after removing the space character there is an extra % character. Try it?

This might be better:
Code:
LOG_NAME_DATE=`date +'%y%m%d-%H%M%S'`

Or even:
Code:
LOG_NAME_DATE=`date +'%Y%m%d-%H%M%S'`


Last edited by methyl; 05-12-2011 at 01:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

9. 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
Login or Register to Ask a Question