LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   Search for keywords and its values from multiple log files (https://www.linuxquestions.org/questions/aix-43/search-for-keywords-and-its-values-from-multiple-log-files-4175581467/)

dfn 06-04-2016 10:00 PM

Search for keywords and its values from multiple log files
 
4 Attachment(s)
My program searches for certain keywords and its values from multiple log files and output the information to a text file and sends email.

One of the Keyword is name real time . if real time row value in the log files is greater than 5:00:00 than output the column name and its value and the filename to progflag.log

In progflag.txt, I am getting headers with no column values.

Code:

MEMSIZE SECOND  SASEXE  FILENAME
Here is what the output results need to show in progflag.txt

Code:


MEMSIZE  SECOND    SASEXE            Filename
200                                    SASFoundation_MEMSIZE.log                     
400      06:00:00  SASFoundation      GT_5hr.log

In the below example, there should be only 2 filenames in the progflag.txt and not three. no_SASFoundation_no_MEMSIZE.log doesn't meet the criteria so there shouldn't be any data for this file in progflag.csv.

[/CODE]
#!/bin/bash

Code:

cd /log/tmp/*.log | awk -F '[=:]' '
  function pr() {printf FORMAT, K[1],K[2],K[3],K[0]}
  BEGIN {FORMAT="%s\t%s\t%16s\t%s\n"
      printf FORMAT, "MEMSIZE","SECOND","SASEXE","Filename\n"
        for(i=split("/Memsize/ $2, ,/Real Time/ $2 ,/SASFoundation/ $3",A,",");i;i--) L[A[i]]=i
      FORMAT="%s\t%.1f\t%16s\t%s\n"
  }
  FNR==1 {
      if(K[1] || K[2]>'5:00:00' || K[3]) pr()
      K[0]=FILENAME
      K[1]=K[2]=K[3]=x
  }
  $1 in L {v=$2;gsub("^[/ ]*","",v);gsub(/ *$/,"",v);K[L[$1]]=v}
  END{if(K[1] || K[2]>'5:00:00' || K[3]) pr()}' *.log > progflag.txt

[ -s progflag.txt ] && mailx -s "subject text" -a  progflag.txt receiver@domain.com < "Code Need to be Evaluated"


NevemTeve 06-05-2016 11:00 PM

First problem in your code: cd /log/tmp/*.log

dfn 06-06-2016 08:25 AM

Thanks


All times are GMT -5. The time now is 09:28 AM.