Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing all text from a active log file 1

Status
Not open for further replies.

DrSeussFreak

Programmer
Feb 16, 2007
149
US
where I run the below code

Code:
objFSO2.CopyFile "D:\oracle\admin\mrf1\bdump\alert_mrf1.log" , "D:\dba_util\scripts\log\alert_mrf1.log", OverwriteExisting

I need to then clear out the original file from which I copied (or delete it), except that it is in use. How can I clear the contents of the original file?

Below is all the code I have

Code:
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("D:\oracle\admin\mrf1\bdump\alert_mrf1.log", _
    ForReading)

strSearchThis = objTextFile.ReadAll
if instr(strSearchThis, "ORA-") > 0 Then
	
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
objFSO2.DeleteFile("D:\dba_util\scripts\log\alert_mrf1.log")
objFSO2.CopyFile "D:\oracle\admin\mrf1\bdump\alert_mrf1.log" , "D:\dba_util\scripts\log\alert_mrf1.log", OverwriteExisting
	SendEmail "To", "From", "MARS - Alert Log Error", strSearchThis
	Else
End If

Sub SendEmail(strTo, strFrom, strSubject, strMsg)
    schema = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/"[/URL]
    SmtpServer = "SMTP"

    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = strFrom
    objEmail.To = strTo
    objEmail.Subject = strSubject
    objEmail.Textbody = strMsg

    objEmail.Configuration.Fields.Item (schema & "sendusing") = 2
    objEmail.Configuration.Fields.Item (schema & "smtpserver") = SmtpServer
    objEmail.Configuration.Fields.Item (schema & "smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
End Sub
 
Instead of CopyFile why don't you just move it (MoveFile)?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
permission denied. I need to write to the file, but essentially, just write nothing, erasing all previous text
 
Open the file for writing and then close it.

objFSO.OpenTextFile("YourFile.log", 2, True)

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
what kills me, is that I can manually delete the file anytime I want. But when I use

Code:
objFSO2.DeleteFile("D:\oracle\admin\mrf1\bdump\alert_mrf1.log")

I get

D:\dba_util\scripts>AlertLog.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

D:\dba_util\scripts\AlertLog.vbs(22, 1) Microsoft VBScript runtime error: Permission denied
 
so if I do

Code:
Const ForWriting = 1

objFSO2.OpenTextFile("D:\oracle\admin\mrf1\bdump\alert_mrf1.log", 2, True)
objFSO2.CloseTextFile

it will be blank?
 
I got it to work, here is my working code

Code:
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("D:\oracle\admin\mrf1\bdump\alert_mrf1.log") Then
Set objTextFile = objFSO.OpenTextFile("D:\oracle\admin\mrf1\bdump\alert_mrf1.log", _
    ForReading)

strSearchThis = objTextFile.ReadAll
Set objTextFile = Nothing
if instr(strSearchThis, "ORA-") > 0 Then
	
Set objFSO2 = CreateObject("Scripting.FileSystemObject")

If objFSO2.FileExists("D:\dba_util\scripts\log\alert_mrf1.log") Then
objFSO2.DeleteFile("D:\dba_util\scripts\log\alert_mrf1.log")
End If
objFSO2.CopyFile "D:\oracle\admin\mrf1\bdump\alert_mrf1.log" , "D:\dba_util\scripts\log\alert_mrf1.log"
objFSO2.DeleteFile("D:\oracle\admin\mrf1\bdump\alert_mrf1.log")
	SendEmail "To", "From", "MARS - Alert Log Error", strSearchThis
	Else
End If

Sub SendEmail(strTo, strFrom, strSubject, strMsg)
    schema = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/"[/URL]
    SmtpServer = "SMTP"

    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = strFrom
    objEmail.To = strTo
    objEmail.Subject = strSubject
    objEmail.Textbody = strMsg

    objEmail.Configuration.Fields.Item (schema & "sendusing") = 2
    objEmail.Configuration.Fields.Item (schema & "smtpserver") = SmtpServer
    objEmail.Configuration.Fields.Item (schema & "smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
End Sub
Else
Set objFSO3 = CreateObject("Scripting.FileSystemObject")

If objFSO3.FileExists("D:\dba_util\scripts\log\alert_mrf1.log") Then
objFSO3.DeleteFile("D:\dba_util\scripts\log\alert_mrf1.log")
End If
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top