grep rexx, um den Protokollzeitstempel einzuschließen

613
anjanbacchu

Ich greife viele Protokolldateien für bestimmte Oracle-bezogene Fehler mit ORA-xxxxx-Fehlercodes. Alle Protokolleinträge beginnen mit einem Zeitstempel (zB: 2017-11-29 23: 51: 46,372). Einige Protokolleinträge sind mehrzeilig - wie diejenigen mit java Ausnahme-Stack-Traces, bei denen die ORA-xxxxx-Codes mit der Zeitmarke tief unter der Protokolleintragszeile liegen.

Wie lautet der reguläre Ausdruck, um den Protokollzeitstempel bis zum ORA-xxxxx-Code zu finden?

Sobald ich den oben genannten regulären Ausdruck erreicht habe, muss er nach Datum sortiert werden, um zu ermitteln, wann ein bestimmter ORA-xxxxx-Fehler zuletzt aufgetreten ist.

PS: Der Befehl grep oder perl regex reicht aus.

Vielen Dank,

Beispiel einer Protokolldatei

2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception during load of zzz javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76) . . .  at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505) Caused by: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2235) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) at org.hibernate.loader.Loader.list(Loader.java:2124) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67) ... 16 more Caused by: java.sql.SQLException: [Mercury][Oracle JDBC Driver][Oracle] ORA-04031: unable to allocate 3896 bytes of shared memory ("shared pool","selec t licensekey0_.ID as ID...","sga heap(1,0)","kglsim object batch") 
1
Suchen Sie nach Datum und Datum (nicht einmal für die Verwendung eines regulären Ausdrucks erforderlich). Prüfen Sie, wann immer die Daten für diese "Zeile" "ORA-xx" enthalten. Seth vor 6 Jahren 0

1 Antwort auf die Frage

1
Toto

Dieser Perl-One-Liner erledigt die Arbeit:

perl -0777 -nE 'say $1 while(/(\d-\d\d-\d\d \d\d:\d\d:\d\d,\d+(?:(?!ORA-\d+)(?!\d-\d\d-\d\d \d\d:\d\d:\d\d,\d+).)*ORA-\d+(?:(?!\d-\d\d-\d\d \d\d:\d\d:\d\d,\d+).)*)/sg)' file.txt 

Dadurch wird der Inhalt der Gruppe 1 ( $1) jedes Mal gedruckt, wenn er gefunden wurde.

Optionen:

-0777 : slurp mode -n : add a loop around the script -E : enable features ("say" in this case) 

Regex:

/ : regex delimiter ( : start group 1 \d-\d\d-\d\d \d\d:\d\d:\d\d,\d+ : regex for date (?: : start non capture group (?! : negative look ahead, make sure we don't have the following ORA-\d+ : literally "ORA-" followed by digits ) : end lookahead (?! : negative look ahead, make sure we don't have the following \d-\d\d-\d\d \d\d:\d\d:\d\d,\d+ : regex for date ) : end lookahead . : any character )* : non capture group is present 0 or more times ORA-\d+ : literally "ORA-" followed by digits (?: : start non capture group (?! : negative look ahead, make sure we don't have the following \d-\d\d-\d\d \d\d:\d\d:\d\d,\d+ : regex for date ) : end lookahead . : any character )* : non capture group is present 0 or more times ) : end group 1, contents in "$1" /sg : regex delimiter, s: single line, g: global 

Eingabedatei Beispiel:

2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception during load of zzz javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) ORA-04031: unable to allocate 3896 bytes of shared memory ("shared pool","selec t licensekey0_.ID as ID...","sga heap(1,0)","kglsim object batch") 2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception during load of zzz javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) (NO ORA.....) unable to allocate 3896 bytes of shared memory ("shared pool","selec t licensekey0_.ID as ID...","sga heap(1,0)","kglsim object batch") 2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception during load of zzz javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) ORA-04031: unable to allocate 3896 bytes of shared memory ("shared pool","selec t licensekey0_.ID as ID...","sga heap(1,0)","kglsim object batch") 

Ergebnis:

2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception during load of zzz javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) ORA-04031: unable to allocate 3896 bytes of shared memory ("shared pool","selec t licensekey0_.ID as ID...","sga heap(1,0)","kglsim object batch")  2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception during load of zzz javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) ORA-04031: unable to allocate 3896 bytes of shared memory ("shared pool","selec t licensekey0_.ID as ID...","sga heap(1,0)","kglsim object batch") 

Der zweite Block wird nicht angezeigt

vielen Dank. Nicht alle Protokolleinträge haben die gleiche Struktur. Einige Einträge haben den ORA-XXXXX in derselben Zeile wie der Zeitstempel. andere haben 3-4 Zeilen und andere mehr. Kann ich 1 Regex haben, um alle Bedingungen zu erfüllen? vielen Dank. anjanbacchu vor 6 Jahren 0
@anjanbacchu: In all diesen Fällen sollte es funktionieren. Toto vor 6 Jahren 0
Danke dir. Ich habe diese Antwort akzeptiert. Nun habe ich den zweiten Teil dieser Frage unter https://superuser.com/questions/1278651/script-to-find-latest-log-entry-for-a-given-ora-xxxxx-code gestellt. Möchten Sie es versuchen? Danke noch einmal, anjanbacchu vor 6 Jahren 0
Gibt es eine Möglichkeit, ** nur ** den Zeitstempel für einen bestimmten ORA-xxxx-Code auszugeben **? anjanbacchu vor 6 Jahren 0
@anjanbacchu: Siehe meine Antwort auf die andere Frage. Toto vor 6 Jahren 0