I have a shell script that used to look for a particular sting in the last line of a log file. Howeve this string now has moved to the 3rd or 4th line from bottom.
Can anyone point me to how i easiest chage this one to look within the last frew lines (5 or so) for the particular string rather than just the very last one.
Here's the code that's used:
Thanks for helping me.
Moderator's Comments:
Please use code tags when posting data and code samples!
Last edited by vgersh99; 05-23-2011 at 08:24 AM..
Reason: code tags, please!
Or you could store the last few lines in temp file and run nawk on it
Hi kumaran_5555,
if i understand you correctly here, you would be replacing the whole of:
while [ "${SUCCESS}" = "FAILED" ]
do
LOGINFO="`/usr/bin/cat "${LOGFILE_NBU}" | /usr/bin/nawk \
'BEGIN{
last_line="";
}
{ # Main
if ($0 != ""){
last_line=$0;
}
} # end of Main
END{
printf("%s",last_line);
}'`"
if [ "${LOGINFO}" != "" ]
then
with just:
tail -5 log_file.txt|while read line
do
echo $line | /usr/bin/nawk \
'BEGIN{
tsys_success="";
success="";
fla_backup=0;
fla_success=0;
number=0;
m=0;
}
{ # main
number=(split($0,arr00,""));
for (m=1; m <= number; m++){
if (index(arr00[m],"User_")>0){
fla_backup=1;
}
if (index(arr00[m],"essfull")>0){
fla_success=1;
}
if ((fla_backup==1) && (fla_success==1)){
success="OK";
printf("%s",success);
}
else{
success="FAILED";
printf("%s",success);
}
} # for loop
}'`" # end of main
fi
I am lost here...?
Thanks for giving me a heads up
The code I opend the thread with is part of a whole compex scipt that seems do been written by somone dunno how to put this.
And I just try to change the code that is there with minimal invasion as possible to the whole thing as there is other code that would rely on the whole script to still work...and the whole thing has got a wrapper round with the loop that the script will look into the log file for 20hours to see if the string will occur. However as pointed out the string simply doesn't occure in the last line anymore so either the whole log file has to get grepped for or at least the last 5 lines...
Thanks for your great help and input!
---------- Post updated at 07:17 AM ---------- Previous update was at 06:40 AM ----------
I am coming up with the following which now should be doing the same but looking into the last 5 lines of the log file:
LEFT_TIME=`expr $CON_TIME_DIFF - $DIFF_TIME` # the time we would wait for success entry in nbulog!
if [ ${DIFF_TIME} -lt ${CON_TIME_DIFF} ]
then
i=0
SUCCESS="FAILED"
while [ "${SUCCESS}" = "FAILED" ]
do
LOGINFO="`/usr/bin/tail -n5 "${LOGFILE_NBU}" | /usr/bin/nawk \
'BEGIN{
last_line="";
}
{ # Main
if ($0 != ""){
last_line=$0;
}
} # end of Main
END{
printf("%s",last_line);
}'`"
if [ "${LOGINFO}" != "" ]
then
SUCCESS="`echo "$LOGINFO" | /usr/bin/nawk \
'BEGIN{
tsys_success="";
success="";
fla_backup=0;
fla_success=0;
number=0;
m=0;
}
{ # main
number=(split($0,arr00,""));
for (m=1; m <= number; m++){
if (index(arr00[m],"User_")>0){
fla_backup=1;
}
if (index(arr00[m],"essfull")>0){
fla_success=1;
}
if ((fla_backup==1) && (fla_success==1)){
success="OK";
printf("%s",success);
}
else{
success="FAILED";
printf("%s",success);
}
} # for loop
}'`" # end of main
fi
Hi,
I have logfile like this..
=== 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header
=== 2015-02-09... (8 Replies)
Bonjour,
I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things.
The script use the following technique :
tail -fn0 $logfile | \
while read line ; do
... some stuff
done
First one, I'd like a way to end the monitoring script if a... (3 Replies)
Hi Team,
Have to write a shell script to pick only 1 hr logs from the generated logfile and send it to other logfile.
Thanks & Regards,
Indu (3 Replies)
Dear all,
I have small script which seems to be working but seems to have some bug.
It suppose to read commonTxt and then print the noOfLines in outputFile.
It is working for most of the txt but unable to add some of the variables values.
Can somebody please spend looking at the thread and... (2 Replies)
Hi,
I need to continuously monitor a logfile to get the log information between a process start and end.
the logfile look like this
abcdddddddddd
cjjckkkkkkkkkkkk
abc : Process started
aaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbb
abc... (6 Replies)
I cannot get anything to go to my log. This is what i see on my screen when i run my korn shell.
cd ok, cwd=/export/home/tsp_inst/TSP
pget: /nas4/edata/tsp/rawdata/test2.gz: File exists
But i cant get it to write it to my log.
cd /this/is/my/newdirectory
lftp -e 'pget -c -n 4... (1 Reply)
Hi,
I have a log file like exyymmdd.log and i need to do is read the log file and inside the logfile if i find the word which starts with PQR002106570.book then i need to replace the value of PQRXXX.book(this is unique) with its corresponding title. A list of id(PQRXXX.book) and its title are... (5 Replies)
I thought I was pretty handy with awk until I got this one. :)
I'm trying to parse a log file where the events could have different delimiters (2 scripts is ok), the errors are spread over multiple lines, and I"m trying to figure out how to not read the same lines that have already been read. ... (1 Reply)
hi
iam new of the ksh script.iwant in formation of how to call in logfile in
ksh scripts. if the meaning in ksh.
please help me
thanks
naveen.g (1 Reply)
hi friends
I need a shell script which will do the following Task
Enter the month :
if you enter 1 then it ll show you last 1 month's (starting from today).log file in the current directry.
if you enter 4 then it ll show you last 4 month's (starting from today).log file in the current... (2 Replies)