Jump to content

looking for string in logfile

- - - - -

  • Please log in to reply
3 replies to this topic

#1
jjlinux

jjlinux

    Newbie

  • Members
  • Pip
  • 3 posts
Hi I have got a script that used to look for a successful string within a log file that so far did occur in t he last line of the log files script.

However this log file now chagned and displays susuccessful in the third last row from bottom upwards. Only once successfull is printed in the entire log file.

What would be the easiest way to change the script.

Attaching the excert from the scritp that does do the lookup (keeps running for 20h)

Main idea is to change this bit to look for the whole nbulog.log file rather than into the last line only

LOGINFO="`/usr/bin/cat "${LOGFILE_NBU}" | /usr/bin/nawk \
'BEGIN{
last_line="";

into something like nawk '/successful/' nbulog.log

Attached Files



#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
grep "successful" $LOGFILE_NBU

At least that is all I could come up with based on your suggestion. Were you looking for successful in a specific place? Just once? I am unsure.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
jjlinux

jjlinux

    Newbie

  • Members
  • Pip
  • 3 posts
Alexander,
thanks for the quick answer...probem is that this is part of a more complex scritp that is there.

And I am looking for something to replace:
LOGINFO="`/usr/bin/cat "${LOGFILE_NBU}" | /usr/bin/nawk \
'BEGIN{
last_line="";

to not only look into the last_line of the LOGFILE_NBU

cheers

#4
jjlinux

jjlinux

    Newbie

  • Members
  • Pip
  • 3 posts
Can anyone help?


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

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

if [ ${i} -lt $LEFT_TIME ]
then
echo "+ + + + INFO :`/usr/bin/date`: Left time(secs) = $LEFT_TIME, WAITED_TIME(secs)=$i !"
echo "+ + + + INFO :`/usr/bin/date`: We are still waiting for the right information in the NBULOGFILE before we could proceed!"
/usr/bin/sleep 60
i=`expr $i + 60`
else
break
fi

done


All this is doing at the moment is looking in the last line of the nbulog.log file....
but the sting wouldn't occur in the last line anymore... it is there but in the 3rd or the 4th line from bottom up.

Can anyone help me pls?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users