Hi there,
my ksh script collects a procstack trace for a particular pid and then greps it by a transaction id to find out the pthread ID:
---------- tid# 1876087 (pthread ID: 4466) ----------
So the pthread ID I want is 4466 in this case, and it is assighed to the variable $pthread. This works fine so far.
After this point, I need to read the first line of a few files whose names are composed by several variables in $HEAD_FILE and a number that it reads from file task2. This currently contains:
32888
So HEAD_FILE will be /logs/eComm_esn_32888.log and the loop will only run once. The first line of this file contains:
1021 2010-03-02 17:06:17 0000-00-00 00:00:00 +0100 00000000 001 003f 0001 09 eComm 32888 893162 4466 /logs/eComm_32888.log 7.8.2.8 [19237] ESN
I want to set a condition that if field number 15 is equal to the pthread ID (4466) it should print the whole line. Otherwise not. AWK has difficulty in reading the first few characters, so I have used sed to replace them with "nothing" (8 dots).
This makes 4466 be in the $14th position now so I can change the condition.
Here�s the relevant part of the script:
## Take a procstack trace of the pid to find the pthread_id
procstack $PID > "${OM}_procstack_${PID}.txt"
pthread=`cat $OM_procstack_$PID.txt |grep $TID | sed -e 's/^.*ID: //' -e 's/).*//g'`
echo " "
echo "------pthread ID corresponding to transaction $TID is $pthread ------" >> $LOG
while read line
do
HEAD_FILE=`head -1 /logs/eComm_${line}.log | sed -e 's/^........//g'`
echo $HEAD_FILE
awk '$14 == 4466 {print $14, $15, $16}' < $HEAD_FILE
done < task2
fi
done < tasks
=======
Running this as it is gives me the following:
2010-03-02 17:06:17 0000-00-00 00:00:00 +0100 00000000 001 003f 0001 09 eComm 32888 893162 4466 /logs/eComm_32888.log 7.8.2.8 [19237] ESN
No such file or directory
./orange.sh[83]: 2010-03-02 17:06:17 0000-00-00 00:00:00 +0100 00000000 001 003f 0001 09 eComm 32888 893162 4466 /logs/eComm_32888.log 7.8.2.8 [19237] ESN: cannot open
=======
So it echoes the value of HEAD_FILE as it understands it now, and the number I am interested in is in 14th position, but I don�t know how to get around the 'cannot open' error to make my condition work.
I only want the 1st line of the file read in the loop which contains the number matching the value of $pthread, obtained a little earlier (4466). Does anyone have any ideas of what I am doing wrong? I think I�ve been staring at this too long..
Thanks in advance!
T.