Help with debug the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with debug the script
# 1  
Old 09-15-2009
Help with debug the script

Hi,
I have this script, searches and sets variables, then searches and sets more variables from multiple files.
I'd need to debug it a bit.

Code:
#!/bin/bash
egrep $1 `find | grep MAGT` >/tmp/resRA-$$
thread=`sed -n '/{0x/ {s/^.*{0x\([0-9a-zA-Z]*\).*/\1/p;q}'  /tmp/resRA-$$`
tag=`sed -n '/Tag=/ {s/^.*Tag=\([0-9a-zA-Z]*\).*/\1/p;q}'  /tmp/resRA-$$`
name=`sed -n '/} {/{s/^.*} {\([a-zA-Z ]*\).*/\1/p;q}' /tmp/resRA-$$`
/tmp/resRA-$$`
echo "thread=$thread"
echo "tag=$tag"
echo "name=$name"
egrep $thread `find | grep MAGT` | grep "$name" >/tmp/res-RB$$
mbsync=`sed -n '/MailSync/ {s/^.*MailSyncId=\([0-9a-zA-Z]*\).*/\1/p;q}'  /tmp/res-RB$$`
echo "MailSyncID=$mbsync"
#grep -- $1 `find | grep MAGT` >/tmp/resB-$$
#tag=`sed -n '/Tag=/ {s/^.*Tag=\([0-9a-zA-Z]*\).*/\1/p;q}'  /tmp/resB-$$`
grep $tag `find | grep DISP` >/tmp/resRC-$$
exttag=`sed -n '/ Tag=/ {s/^.*Tag=\([0-9a-zA-Z]*\).*/\1/p;q}'  /tmp/resRC-$$`
echo
echo "[QM/SC]"
egrep $mbsync `find | egrep 'GWQM|GWSC'`
echo
echo [MAGT]
egrep "$1|$tag" `find | grep MAGT`
echo
echo [DISP]
egrep "$tag|$exttag" `find | grep DISP`
echo [GWCO]
egrep "$1" `find| grep GWCO`

Sometimes there is no results of command like `find | grep MAGT` or no variable has been found and script just hung on that or produces tons of garbage.
How could I get the condition for each command if some variable=0 or the file is empty, then print error message and terminate the script?
It should be easy task, but if someone can give me advice as well as if I can make syntax more simple it will be much appreciative.

Cheers
# 2  
Old 09-15-2009
Not clear what you are trying to do.
In all of these selected command lines the combination of `find | grep` or `find | egrep` just processes a syntax error from "find". The position in the command line suggests that you are trying to generate a filename (or filenames?).

Quote:
egrep $1 `find | grep MAGT` >/tmp/resRA-$$

egrep $thread `find | grep MAGT` | grep "$name" >/tmp/res-RB$$

grep $tag `find | grep DISP` >/tmp/resRC-$$

egrep $mbsync `find | egrep 'GWQM|GWSC'`

egrep "$1|$tag" `find | grep MAGT`

egrep "$tag|$exttag" `find | grep DISP`

egrep "$1" `find| grep GWCO`
Are you trying to search the current directory for files containing a string (for example "MAGT") ?

What value is in the script parameter $1 , and what does is mean?
# 3  
Old 09-17-2009
Well I have bunch of log files, their names contains MAGT, DISP GWCO etc..., inside the files there is many lines like
Code:
[40000] (06/18 00:16:37.077):{0x22A0} {Hofer, Marc} PopulateMessage mbsync=1454490, RefId=0, Delivered=Thu Jun 18 00:16:28 2009 GWID=4A39875C.AT-W-SD.AT-WIEN.100.136306C.1.4C0A2.1
[40287] (06/18 00:16:37.186):{0x22A0} {Hofer, Marc} Queuing message, RefId=-1323204051, EntryId=43596, Posted=06/18 00:16:28

task is to supply parameter refid=$1(-1323204051), then find another variable thread=0x22A0, then mbsync=1454490

I can then use variable $mbsync to search in another file for another variables and when I get all variables needed I will then display all important lines with variables on the end of the script.

> /tmp/resRA-$$ generated random file, it's used for sed to filter the actual variable, this method may be difficult, but I've never had any problem with it, but if there is any easier way I will be happy to use it.

I wanted as well to make script managing different input variables like supply GWID instead of the refid and do the same procedure, but don't know how to do it. As a workaround I have another script with the same code but $1 is not refid but GWID.

Cheers

Last edited by Vitoriung; 09-18-2009 at 05:45 AM..
# 4  
Old 09-18-2009
You might help us help you better if you could provide a better description of the problem you want to solve. I suggest that you:
  1. Give us a psuedo code version of the algorithm you want to implement
  2. Specifiy what the data files contain
  3. note any special knowledge like you need the value of some field that appears in a line before you reach the line that tells you that you need it
  4. specify what set of information completes a data set
  5. specify the output format
  6. specify what is fixed information and what is variable
# 5  
Old 09-18-2009
Change
Code:
egrep $1 `find | grep MAGT` >/tmp/resRA-$$

to
Code:
find . -name '*MAGT*' |xargs egrep "$1" >/tmp/resRA-$$

# 6  
Old 09-25-2009
Description

Quote:
Originally Posted by jp2542a
You might help us help you better if you could provide a better description of the problem you want to solve. I suggest that you:
  1. Give us a psuedo code version of the algorithm you want to implement
  2. Specifiy what the data files contain
  3. note any special knowledge like you need the value of some field that appears in a line before you reach the line that tells you that you need it
  4. specify what set of information completes a data set
  5. specify the output format
  6. specify what is fixed information and what is variable
OK I will try to give the info, hopefully it will help to understand my issue and it's not confusing too much:

1. Pseudo code version? I am not sure if I understand the question, I want to supply one fixed parameter and find all the other variables logically connected to that fixed parameter, all those exists in multiple log files.

2. Data files are the logs;contain the various data like debug information, system and connection messages. It's on the server processing emails and other items like PIM etc. and every day generates the logs as follows:
*GWSC* or *GWQM* - connects to email system checking for new emails
*MAGT* - connects to emails system to pickup the email
*DISP* - gets the email from *MAGT* and forwards to recipient
*GWCO* logs changes in the existing email system (reads, deletes, etc..)

3. All what I need to know is one input parameter. Depends on what one do I actually have.
Most of the time it's $refid, but it can be $IceID, or $tag
example of the lines I am looking for -
Code:
[QM/SC]
[34006] (07/23 09:04:42):{0x410} {12} {Buly, Paul} MTH: New Message, RefId=0, ICEId=4A68279B.GWDOM2.GWPO03.100.16C6236.1.166AC.1, MailSyncID=9629454, ObjectDefnId=1000, Successful=True

[MAGT]
[40435] (07/23 09:04:43.918):{0x21CC} {Buly, Paul} Queuing new mail through notification. EntryId=373748. Msgs Pending 0
[40000] (07/23 09:04:43.918):{0x21CC} {Buly, Paul} Get MAIL {9629454} A68279B.GWDOM2.GWPO03.100.16C6236.1.166AC.1 from the mailbox
[40000] (07/23 09:04:44.121):{0x21CC} {Buly, Paul} PopulateMessage MailSyncID=9629454, RefId=0, Delivered=Thu Jul 23 09:04:27 2009 GWID=4A68279B.GWDOM2.GWPO03.100.16C6236.1.166AC.1
[30085] (07/23 09:04:44.136):{0x21CC} {Buly, Paul} New mail has arrived, EntryId=373748
[40287] (07/23 09:04:44.136):{0x21CC} {Buly, Paul} Queuing message, RefId=-2007620944, EntryId=373748, Posted=07/23 09:04:27
[30081] (07/23 09:04:44.168):{0x21E8} {Buly, Paul} Sending message, size=310, EntryId=373748, RefId=-2007620944, TransactionId=-900822891, Tag=9586876
[40279] (07/23 09:04:44.168):{0x21E8} {Buly, Paul} SubmitToRelaySendQ, Tag=9586876
[40287] (07/23 09:04:44.136):{0x21CC} {Buly, Paul} Queuing message, RefId=-2007620944, EntryId=373748, Posted=07/23 09:04:27
[30097] (07/23 09:04:45.277):{0x10C4} {Buly, Paul} Message has been delivered, Tag=9586876, EntryId=373748

[DISP]
[30222] (07/23 09:04:44.168):{0x11E8} {Buly, Paul} MTH: contentType=CMIME, sizeOTA=274, sizeOTW=274, TransactionId=-900822891, Tag=13662827
[30310] (07/23 09:04:44.168):{0x11E8} {Buly, Paul} Forwarding internal data, contentType=CMIME, routing=S36822534,  size=312, cmd=0x3, ack=0, TransactionId=-900822891, intTag=9586876, Tag=13662827, Submit=1
[30368] (07/23 09:04:45.277):{0x21DC} {Buly, Paul} Packet has been delivered, Tag=13662827
[30388] (07/23 09:04:45.277):{0x21DC} [BIPPa] {Buly, Paul} Forwarding status to Agent (S36822534_001), intTag=9586876, extTag=13662827

[GWCO]
[34022] (07/23 09:28:06):{0x86C} {4} {Buly, Paul} MTH: Delete Message, RefId=-2007620944, ICEId=4A68279B.GWDOM2.GWPO03.100.16C6236.1.166AC.1, MailSyncId=9629454, ObjectDefnId=7000, Successful=True

This is just the filtered output as it should be visible after successful searching.
Supplying the $refid shows what other parameters to search for to get the information from other files -
$refid needs $threadID=0x21CC to find MailSyncID and search for it in the *GWSC(QM)* file.
Problem is when the system fails and some items were not delivered, then I need the script to acknowledge me about it so I can see where is the point of the failure.
for example -
Code:
[QM/SC]
[34006] (07/23 09:04:42):{0x410} {12} {Buly, Paul} MTH: New Message, RefId=0, ICEId=4A68279B.GWDOM2.GWPO03.100.16C6236.1.166AC.1, MailSyncID=9629454, ObjectDefnId=1000, Successful=True

[MAGT]
[40435] (07/23 09:04:43.918):{0x21CC} {Buly, Paul} Queuing new mail through notification. EntryId=373748. Msgs Pending 0
[40000] (07/23 09:04:43.918):{0x21CC} {Buly, Paul} Get MAIL {9629454} A68279B.GWDOM2.GWPO03.100.16C6236.1.166AC.1 from the mailbox
[40000] (07/23 09:04:44.121):{0x21CC} {Buly, Paul} PopulateMessage MailSyncID=9629454, RefId=0, Delivered=Thu Jul 23 09:04:27 2009 GWID=4A68279B.GWDOM2.GWPO03.100.16C6236.1.166AC.1
[30085] (07/23 09:04:44.136):{0x21CC} {Buly, Paul} New mail has arrived, EntryId=373748
[40287] (07/23 09:04:44.136):{0x21CC} {Buly, Paul} Queuing message, RefId=-2007620944, EntryId=373748, Posted=07/23 09:04:27
[30081] (07/23 09:04:44.168):{0x21E8} {Buly, Paul} Sending message, size=310, EntryId=373748...error sending message, uknown exception

[DISP]

[GWCO]
in this case $tag doesn't exist, so script should not search for it in other files and stop where the error is.

4. specify what set of information completes a data set - described in ad 3. ?

5. Output - I don't know what type of output can I have actually, suppose it could be e.g. XML file? Output would be fine as just text displayed in the console

6. fixed information is RefID in this script, variables are all the other ($mailsyncid, $tag, $ICEID ...) I'd like to have an option to supply any fixed information and search for relevant other variables. Typically I get $RefId or $ICEId when user reports the email hasn't been delivered.

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. Shell Programming and Scripting

Debug perl script

Hi, I am trying to get squid up and running using a redirector process, and every time I try to load a web page, squid fails miserably. Can some one with perl and squid knowledge take a look at these codes and tell if something is wrong here. #!/usr/bin/perl # $| = 1; @endings = qw/... (0 Replies)
Discussion started by: jamie_123
0 Replies

3. Shell Programming and Scripting

Debug script already running

Hello, is it possible to debug a script that is already running "on-demand"? Somehow a command like "set -x" but once you've executed the script. And another one to disable debugging? Thank you (0 Replies)
Discussion started by: asanchez
0 Replies

4. Shell Programming and Scripting

Cant debug shell script

Hi I am relatively new in shell scripting Below is the code which i developed but for some reason, it keeps giving me error: /apps/bss/BatchProg/at1/batch/scripts/ksh/TBATLC02.ksh: syntax error at line 41 : `then' unmatched #!/usr/bin/ksh... (4 Replies)
Discussion started by: scripting_newbe
4 Replies

5. Shell Programming and Scripting

Problem with the script, help me debug

Hi, When i run the script ./script.sh sun, this give me no output, it should give me the list of file. If i run the script without the argument it should send me echo inside usage(). What is the problem? please help -Adsi #!/bin/sh ROOT_PATH=/net/icebox/vol/local_images/spins... (2 Replies)
Discussion started by: asirohi
2 Replies

6. Shell Programming and Scripting

If condition error-please debug my script

Hi All, I have a script which is based on calculating current time The script looks like this: whenever i try to run the script it gives me error:Please advice wherther i have made mistake with if condition or with for loop?? The code : set -x #!/usr/bin/ksh set -x... (7 Replies)
Discussion started by: usha rao
7 Replies

7. UNIX for Advanced & Expert Users

How can debug our UNIX shell script?

Hi all, i have two simple questions here... 1. i want to know that how to debug the UNIX shell script? 2. is there any way to handling the exception in UNIX shell script like oracle exception handling? Please provide me those details it would be great help/ Thanks and Regards, MPS... (3 Replies)
Discussion started by: psiva_arul
3 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. Shell Programming and Scripting

How to debug the awk script

Hi, How can I debug an awk script? I know that set -x can be used to debug a script. But this will not suite for awk scripts. Can anyone help me? Thanks in advance, Chella (2 Replies)
Discussion started by: chella
2 Replies

10. Shell Programming and Scripting

Debug an Awk Script

I would like to extract the following fields from the text file attached. I copied the contents from a pdf file and pasted them into the text file so I can use awk to extract them. The layout is as listed below. name1,name2,name3,name4,Title,designation,nationality,dob, national ... (1 Reply)
Discussion started by: mboro
1 Replies
Login or Register to Ask a Question