Posts tonen met het label grep. Alle posts tonen
Posts tonen met het label grep. Alle posts tonen

woensdag 26 september 2012

Bash search logfiles

Bash search logfiles

LogFile example
2012-09-16 19:06:33,450 ERROR [-59] JDBCException ORA-00001: unique constraint (X_UK1) violated
2012-09-16 19:31:39,319 ERROR [-60] JDBCException ORA-00060: deadlock detected (X_UK3) violated
2012-09-16 19:31:39,998 ERROR [-61] JDBCException ORA-00001: unique constraint (X_UK1) violated
2012-09-16 19:41:31,331 ERROR [-62] JDBCException ORA-00001: unique constraint (X_UK2) violated
First option is to grep the lines with ORA-00060:
$ grep ORA-00060 l.log 
2012-09-16 19:31:39,319 ERROR [-60] JDBCException ORA-00060: deadlock detected (X_UK3) violated
Find ORA error strip first part of the line.
$ grep ORA l.log | sed 's/.*ORA/ORA/g' 
ORA-00001: unique constraint (X_UK1) violated
ORA-00060: deadlock detected (X_UK3) violated
ORA-00001: unique constraint (X_UK1) violated
ORA-00001: unique constraint (X_UK2) violated
Search for ORA and count the time they occur.
$ grep ORA l.log | sed 's/.*ORA/ORA/g' | sort | uniq -c
   2 ORA-00001: unique constraint (X_UK1) violated
   1 ORA-00001: unique constraint (X_UK2) violated
   1 ORA-00060: deadlock detected (X_UK3) violated
Search with sed between two dates.
$ sed -n '/^2012-09-16 19:31/p; /^2012-09-16 19:32/q' l.log 
2012-09-16 19:31:39,319 ERROR [-60] JDBCException ORA-00060: deadlock detected (X_UK3) violated
2012-09-16 19:31:39,998 ERROR [-61] JDBCException ORA-00001: unique constraint (X_UK1) violated