Display only the specified content.
Hi Friends,
I am using the below script which will search for the word "ORA-" in a file and after that i am writing the output to a file.
Sample of the text file.
I would like to know is there any option available to search for the word "ORA-" in the file based on the time range, so that it will display only the contents of the file after "Mon Feb 15 02:15:00 2010" as specified in the file.
I am using the below script which will search for the word "ORA-" in a file and after that i am writing the output to a file.
<job>
<runtime>
<description>This script reads the alert log of an Oracle Instance</description>
<named
name = "log"
helpstring = "Alert.log to read"
type = "string"
required = "true"
/>
<example>Example: ReadAlert.vb.wsf /log:"c:\oracle\10.1.0\admin\orcl\bdump\alert_orcl.log"</example>
</runtime>
<script language="VBScript">
If WScript.Arguments.Count <> 1 Then
WScript.Arguments.ShowUsage
WScript.Quit
End If
ReadAlert (Wscript.Arguments.Named.Item("log"))
Sub ReadAlert(alertlog)
Dim fso, stream, line, errarray
Const ForReading = 1
' get a handle on the file system
Set fso = CreateObject("Scripting.FileSystemObject")
' try opening the file
Set stream = fso.OpenTextFile(alertlog, ForReading)
' Read the contents of the alert log
do while stream.AtEndOfStream = False
line = stream.ReadLine
if instr(1,line,"ORA-",1) = 1 then ' found error
errarray = split(line," ",2)
errcode = errArray(0)
errmsg = errArray(1)
Wscript.Echo errcode & " in Alert.log " & vbcrlf & "Further Information: " & errmsg
end if
loop
stream.Close
set stream = Nothing
set fso = Nothing
End Sub
</script>
</job>
Sample of the text file.
Mon Feb 15 00:00:01 2010
Errors in file e:\oradba\test\bdump\test_j004_19524.trc:
ORA-12012: error on auto execute of job 159788
ORA-22289: cannot perform FILECLOSE operation on an unopened file or LOB
ORA-06512: at "SYS.DBMS_LOB", line 493
ORA-22288: file or LOB operation GETLENGTH failed
The system cannot find the file specified.
ORA-06512: at line 1
Mon Feb 15 00:15:00 2010
Immediate Kill Session#: 833, Serial#: 43
Immediate Kill Session: sess: 4CEBD720 OS pid: 14512
Mon Feb 15 00:15:20 2010
Thread 1 advanced to log sequence 56185 (LGWR switch)
Current log# 5 seq# 56185 mem# 0: E:\ORADATA\test\testREDO05A.LOG
Current log# 5 seq# 56185 mem# 1: E:\ORADATA\test\testREDO05B.LOG
Mon Feb 15 00:23:07 2010
Thread 1 advanced to log sequence 56186 (LGWR switch)
Current log# 1 seq# 56186 mem# 0: E:\ORADATA\test\testREDO01A.LOG
Current log# 1 seq# 56186 mem# 1: E:\ORADATA\test\testREDO01B.LOG
Mon Feb 15 00:44:26 2010
Thread 1 advanced to log sequence 56187 (LGWR switch)
Current log# 2 seq# 56187 mem# 0: E:\ORADATA\test\testREDO02A.LOG
Current log# 2 seq# 56187 mem# 1: E:\ORADATA\test\testREDO02B.LOG
Mon Feb 15 01:11:09 2010
Thread 1 advanced to log sequence 56188 (LGWR switch)
Current log# 3 seq# 56188 mem# 0: E:\ORADATA\test\testREDO03A.LOG
Current log# 3 seq# 56188 mem# 1: E:\ORADATA\test\testREDO03B.LOG
Mon Feb 15 01:15:00 2010
Immediate Kill Session#: 794, Serial#: 345
Immediate Kill Session: sess: 4CE8CEC8 OS pid: 13828
Immediate Kill Session#: 819, Serial#: 801
Immediate Kill Session: sess: 4CEAC070 OS pid: 18596
Immediate Kill Session#: 823, Serial#: 815
Immediate Kill Session: sess: 4CEB1010 OS pid: 19932
Mon Feb 15 01:42:14 2010
Thread 1 advanced to log sequence 56189 (LGWR switch)
Current log# 4 seq# 56189 mem# 0: E:\ORADATA\test\testREDO04A.LOG
Current log# 4 seq# 56189 mem# 1: E:\ORADATA\test\testREDO04B.LOG
Mon Feb 15 02:11:04 2010
Thread 1 advanced to log sequence 56190 (LGWR switch)
Current log# 5 seq# 56190 mem# 0: E:\ORADATA\test\testREDO05A.LOG
Current log# 5 seq# 56190 mem# 1: E:\ORADATA\test\testREDO05B.LOG
Mon Feb 15 02:15:00 2010
Immediate Kill Session#: 851, Serial#: 6
Immediate Kill Session: sess: 4CED3D70 OS pid: 19800
Mon Feb 15 02:39:26 2010
Thread 1 advanced to log sequence 56191 (LGWR switch)
I would like to know is there any option available to search for the word "ORA-" in the file based on the time range, so that it will display only the contents of the file after "Mon Feb 15 02:15:00 2010" as specified in the file.
0 Comments
[ + ] Show comments
Answers (5)
Please log in to answer
Posted by:
Jsaylor
14 years ago
You could use a simple flag value to accomplish what you're looking for. It would look something like the following:
It's a pretty crude method, but you essentially ignore the second if until the first if is satisfied at least once.
if instr(1,line,"Mon Feb 15",1) then
vflag = 1
End If
if instr(1,line,"ORA-",1) and vflag = 1 Then
Do stuff here
End If
It's a pretty crude method, but you essentially ignore the second if until the first if is satisfied at least once.
Posted by:
nokiak810
14 years ago
Hi Jsaylor,
Thanks for your input. I have used the below one,
The output for tod and tod1 is
Fri Feb 19 00
Fri Feb 19 01
In the file file which i used to scan, i would like to get the "ORA-" error between the above two timings.
if instr(1,line,tod,1) <= instr(1,line,tod1,1) then
vflag = 1
End If
if instr(1,line,"ORA-",1) and vflag = 1 Then
Do stuff here
End If
I have altered as above but couldn't get the output. Please guide me.
Thanks for your input. I have used the below one,
c=now()
d=weekdayname(weekday(c),true)
m=monthname(month(c),true)
da=day(c)
ti=formatdatetime(c,4)
tiadd=dateadd("h",1,c)
tiaddfor=formatdatetime(tiadd,4)
ts=mid(ti,1,2)
ts1=mid(tiaddfor,1,2)
tod=d& " " &m& " " &da& " "&ts
tod1=d & " " &m& " " &da& " " &ts1
The output for tod and tod1 is
Fri Feb 19 00
Fri Feb 19 01
In the file file which i used to scan, i would like to get the "ORA-" error between the above two timings.
if instr(1,line,tod,1) <= instr(1,line,tod1,1) then
vflag = 1
End If
if instr(1,line,"ORA-",1) and vflag = 1 Then
Do stuff here
End If
I have altered as above but couldn't get the output. Please guide me.
Posted by:
anonymous_9363
14 years ago
I'd completely abandon the method you're using for parsing the file. Instead, I'd simply search the file until I get to the line containing the first timing. Then I'd cycle through the remaining lines, adding them to an array, until I get to the line containing the second timing. All that remains then is to loop through the array searching for the required string and do whatever it is you need to do with it.
Actually, I'd use ReadAll first, to avoid the pain of looping through the file line-by-line.
Actually, I'd use ReadAll first, to avoid the pain of looping through the file line-by-line.
Posted by:
nokiak810
14 years ago
Posted by:
anonymous_9363
14 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.