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.

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

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

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?

Well I have bunch of log files, their names contains MAGT, DISP GWCO etc..., inside the files there is many lines like

[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

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

Change

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

to

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

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 -

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

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

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

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

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