抓取SHELL日誌中DB2錯誤

抓取SHELL日誌中DB2錯誤

日常工作中,使用腳本處理DB2數據會記錄些日誌,有時可能會對日誌文件提取是否有報錯信息,本文即時對日誌文件的報錯信息進行的提取。

#! /bin/awk -f

#生成變量
BEGIN {
 i=1
}

#匹配以SQL0開頭SQLSTATE爲結尾的行,把匹配的行賦值給數組stu
/^SQL0/{t=1}{
 if(t)s=length(s)?s"\n"$0:$0
}
/SQLSTATE/{
 t=0;
 stu[i]=s;
 i++;
 s=""
}

#輸出STU
END {
 a=1
 do
 {
  print stu[a]
  ++a;
 }while(a<=length(stu))
}

下面是執行腳本:

[root@ETL TEST]$ ./code1.sh /tmp/DB2_test.log 
THIS TEST
SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table.  SQLSTATE=02000
SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a 
query is an empty table.  SQLSTATE=02000
SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table.  SQLSTATE=02000
SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table.  SQLSTATE=02000
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章