how to print out the error mesaage that is around the oraErr

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
flaskvacuum
Posts: 43
Joined: 08 Mar 2013 11:23

Re: how to print out the error mesaage that is around the or

#16 Post by flaskvacuum » 03 Apr 2013 03:30

ok.. let me sort out my thots . tks for the replies so far.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: how to print out the error mesaage that is around the or

#17 Post by dbenham » 03 Apr 2013 04:30

My What are the undocumented features and limitations of the Windows FINDSTR command? StackOverflow Q&A has a section explaining how to use FINDSTR to search across line breaks.

This small bit of code:

Code: Select all

@echo off
setlocal enableDelayedExpansion
::Define LF variable containing a linefeed (0x0A)
set LF=^


::Above 2 blank lines are critical - do not remove

::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

::Now print each error timestamp and error line
findstr /r /c:"!CR!*!LF!.*!CR!*!LF!ORA-[0-9]" /c:"^ORA-[0-9]" alert_L1UAT2.log
produces the following output

Code: Select all

Tue Mar 12 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []

If you must have the timestamp and error message combined into 1 line, then a bit more code is needed:

Code: Select all

@echo off
setlocal
::Define LF variable containing a linefeed (0x0A)
set LF=^


::Above 2 blank lines are critical - do not remove

::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

::Now use FINDSTR to find the timestamp and error lines
::and use FOR /F to process the results, combining each timestamp and
::error pair into 1 line.
set /a N=1
for /f "delims=" %%A in (
  'cmd /v:on /c findstr /r /c:"!CR!*!LF!.*!CR!*!LF!ORA-[0-9]" /c:"^ORA-[0-9]" alert_L1UAT2.log'
) do 2>nul set /a 1/((N+=1)%%2)&&echo %%A||<nul set /p "=%%A "
--OUTPUT--

Code: Select all

Tue Mar 12 10:47:24 SST 2013 ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []


Dave Benham

flaskvacuum
Posts: 43
Joined: 08 Mar 2013 11:23

Re: how to print out the error mesaage that is around the or

#18 Post by flaskvacuum » 08 Apr 2013 04:37

tks dbenham for the reply.

but is it too advance for me to understand. tried but fail to understand the recommended link.
let me try to re- visit again.

below are the file format:

Code: Select all

Tue Feb 08 10:47:24 SST 2013
Errors in file /opt/ora10g/admin/OCEAN/udump/ocean_ora_27065.trc:
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 09 10:47:24 SST 2013
Errors in file /opt/ora10g/admin/OCEAN/udump/ocean_ora_27065.trc:
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 10 10:47:24 SST 2013
Errors in file /opt/ora10g/admin/OCEAN/udump/ocean_ora_27065.trc:
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Mon Mar 11 06:08:03 SST 2013
Thread 1 advanced to log sequence 236 (LGWR switch)
Current log# 2 seq# 236 mem# 0: /OCEAN_2/OCEAN/oradata/redo02a.log
Current log# 2 seq# 236 mem# 1: /OCEAN_2/OCEAN/oradata/redo02b.log
Thu Mar 14 00:47:42 SST 2013
Thread 1 advanced to log sequence 237 (LGWR switch)
Current log# 3 seq# 237 mem# 0: /OCEAN_2/OCEAN/oradata/redo03a.log
Current log# 3 seq# 237 mem# 1: /OCEAN_2/OCEAN/oradata/redo03b.log
Tue Mar 17 10:47:24 SST 2013
Errors in file /opt/ora10g/admin/OCEAN/udump/ocean_ora_27065.trc:
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Mar 18 11:47:24 SST 2013
Errors in file /opt/ora10g/admin/OCEAN/udump/OCEAN_ora_24269.trc  (incident=32580):
ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []
Incident details in: /opt/ora10g/admin/OCEAN/udump/incident/incdir_32580/ESUBUAT_ora_24269_i32580.trc
Errors in file /opt/ora10g/admin/OCEAN/udump/incident/incdir_32580/ESUBUAT_ora_24269_i32580.trc:
ORA-00308: cannot open archived log '/opt/ora10g/admin/OCEAN/udump/arch/OCEAN_1_3948_730568929.arc'
ORA-27037: unable to obtain file status
HPUX-ia64 Error: 2: No such file or directory
Additional information: 3
ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []
Use ADRCI or Support Workbench to package the incident.
See Note 411.1 at My Oracle Support for error and packaging details.


i need to get all the ORA-error with its timestamp.
so it should look like:

Code: Select all

Tue Feb 08 10:47:24 SST 2013 
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 09 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 10 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Mar 17 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Mar 18 11:47:24 SST 2013
ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []
ORA-00308: cannot open archived log '/opt/ora10g/admin/OCEAN/udump/arch/OCEAN_1_3948_730568929.arc'
ORA-27037: unable to obtain file status
ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []


i am still trying on this code with the help from foxidrive:

Code: Select all

for /F "delims=" %%a in ('findstr "ORA- SST" "alert_L1UAT_test.log"') do (
         set "text=%%a"
     
    if not "!text:ORA-=!"=="!text!" (
         >>"%tempfile%" echo !d8! %%a>>%output%
         )
            set d8=%%a
          )


it output is weird:

Code: Select all

Tue Feb 08 10:47:24 SST 2013 ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 09 10:47:24 SST 2013 ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 10 10:47:24 SST 2013 ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Mar 17 10:47:24 SST 2013 ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], [] ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], [] ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], [] ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], [] ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Mar 18 11:47:24 SST 2013 ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], [] ORA-00308: cannot open archived log '/opt/ora10g/admin/OCEAN/udump/arch/OCEAN_1_3948_730568929.arc'
ORA-00308: cannot open archived log '/opt/ora10g/admin/OCEAN/udump/arch/OCEAN_1_3948_730568929.arc' ORA-27037: unable to obtain file status
ORA-27037: unable to obtain file status ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []




the bottom looks like its being duplicated.

Not too sure i have make myself clear with what i want. Sorry guys, first time writing bash script and find that it is quite steep. :|

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: how to print out the error mesaage that is around the or

#19 Post by dbenham » 08 Apr 2013 09:41

You failed to properly identify your requirements. Your desired output from your last post does not follow your previously stated goal: " i wanted to catch those ORA-ERROR and also print out the line above it (2 line before the error match) to show the timing ."

I reverse engineered your requirements by looking at your newly posted sample file and desired result.

Your source file can be divided into sections, each section starting with a timestamp, followed by any number of lines that may or may not include an ORA- error message.

You want to keep all ORA- error messages, along with their associated timestamps. But you cannot simply include every line that is 2 lines above an ORA- error message.

My original post satisfied your original (erroneous) request. Here is a modified version that satisfies your newly implied requirements

Code: Select all

@echo off
setlocal enableDelayedExpansion
:: Define LF variable containing a linefeed (0x0A)
set LF=^


:: Above 2 blank lines are critical - do not remove

::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

:: Now print out all ORA- errors along with their associated timestamps
findstr /br "Sun\> Mon\> Tue\> Wed\> Thu\> Fri\> Sat\> ORA-[0-9]*:" alert_L1UAT_test.log|findstr /r "!CR!*!LF!ORA- ^ORA-"
--OUTPUT--

Code: Select all

Tue Feb 08 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 09 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Feb 10 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Mar 17 10:47:24 SST 2013
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [kcblasm_1], [103], [], [], [], [], [], []
Tue Mar 18 11:47:24 SST 2013
ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []
ORA-00308: cannot open archived log '/opt/ora10g/admin/OCEAN/udump/arch/OCEAN_1_3948_730568929.arc'
ORA-27037: unable to obtain file status
ORA-00600: internal error code, arguments: [kzaxpopr14 - Error in decoding xml text], [], [], [], [], [], [], [], [], [], [], []


The code is not complex.
First it defines a LF variable that contains a linefeed character, then a CR variable that contains a carriage return character. You don't have to understand how the code works, just copy it and use it.

Those characters are what terminate lines in a Windows text file. The variables are used later in the FINDSTR command.

The main bit of code can be divided into 2 parts.

part 1) Use FINDSTR to preserve all timestamps and all ORA- errors.

The search string is actually composed of 8 distinct searches, delimited by spaces. Any line that matces at least one of the searches is preserved.

The /b option forces the search to only match what appears at the beginning of a line.

The /r option forces the search to be interpreted as a regular expression.

The first six searches are simply the abbreviations for the days of the week, followed by a regex expression that means only match a whole word. So "Mon\>" will not match something like "Monthly".

The last search looks for "ORA-", followed by a string of digits, followed by a colon.

The results of the 1st part would include timestamps that do not have any ORA- errors following them. You do not want timestamps that are not associated with ORA- errors.

part 2) pipe the results of part 1 into a second FINDSTR that preserves any line that immediately precedes an ORA- error, as well as all ORA- errors.

Again, the /r option forces a regex search.

There are 2 searches

The first search looks for a line that precedes an ORA- error. It looks for the line terminater that immediately precedes "ORA-". The * after the !CR! means the carriage return is optional. This allows the script to work with both Windows and Unix text formats. (Unix lines are terminated by a single linefeed).

The second search starts with "^", which means the search must match the beginning of the line. It looks for any line that starts with "ORA-".


Dave Benham

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: how to print out the error mesaage that is around the or

#20 Post by Squashman » 08 Apr 2013 10:18

flaskvacuum wrote:Sorry guys, first time writing bash script and find that it is quite steep. :|

BASH is a Unix/Linux based shell.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: how to print out the error mesaage that is around the or

#21 Post by dbenham » 08 Apr 2013 10:26

I just realized that my solution does not need to search for the carriage return since it is only looking at the very next line. The carriage return only has to be matched if trying to look more than one line ahead.

Here is a simplified version that works.

Code: Select all

@echo off
setlocal enableDelayedExpansion
:: Define LF variable containing a linefeed (0x0A)
set LF=^


:: Above 2 blank lines are critical - do not remove

:: Now print out all ORA- errors along with their associated timestamps
findstr /br "Sun\> Mon\> Tue\> Wed\> Thu\> Fri\> Sat\> ORA-[0-9]*:" alert_L1UAT_test.log|findstr /r "!LF!ORA- ^ORA-"


Dave Benham

flaskvacuum
Posts: 43
Joined: 08 Mar 2013 11:23

Re: how to print out the error mesaage that is around the or

#22 Post by flaskvacuum » 09 Apr 2013 00:16

thanks Dave.B

it helps me in understanding your code with another example of yours:

Code: Select all

Assume TEXT.TXT has these contents (could be Unix or Windows style)

A
A
A
B
A
A

Then this script

@echo off
setlocal
::Define LF variable containing a linefeed (0x0A)
set LF=^

::Above 2 blank lines are critical - do not remove

::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

setlocal enableDelayedExpansion
::regex "!CR!*!LF!" will match both Unix and Windows style End-Of-Line
findstr /n /r /c:"A!CR!*!LF!A" TEST.TXT

gives these results

1:A
2:A
5:A


dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: how to print out the error mesaage that is around the or

#23 Post by dbenham » 09 Apr 2013 06:40

Yep, that is exactly why I provided the link in my first answer. :)

Dave Benham

flaskvacuum
Posts: 43
Joined: 08 Mar 2013 11:23

Re: how to print out the error mesaage that is around the or

#24 Post by flaskvacuum » 09 Apr 2013 07:58

Was thinking how to only show 1week of the alert log timestamp ....cos when the log timestamp grows the previous timestamp that is older then 1week is not necessary.

so far:

Code: Select all

set CurDate=13Jan2012
set yr=%Date:~-4,4%
set mth=%DATE:~-7,2%
set dte=%DATE:~-10,2%
if %mth% == 01 set mth=Jan
if %mth% == 02 set mth=Feb
if %mth% == 03 set mth=Mar
if %mth% == 04 set mth=Apr
if %mth% == 05 set mth=May
if %mth% == 06 set mth=Jun
if %mth% == 07 set mth=Jul
if %mth% == 08 set mth=Aug
if %mth% == 09 set mth=Sep
if %mth% == 10 set mth=Oct
if %mth% == 11 set mth=Nov
if %mth% == 12 set mth=Dec

set CurDate=%dte%%mth%%yr%


is there a way to feed into the pipe to further filter it:

Code: Select all

findstr /br "Sun\> Mon\> Tue\> Wed\> Thu\> Fri\> Sat\> ORA-[0-9]*:" alert_L1UAT_test.log|findstr /r "!CR!*!LF!ORA- ^ORA-" | findstr  ??? 


Post Reply