Hi, I am trying to combine 2 VBScripts to make a VBScript that will search a logfile for errors and send an email. I'm not familar with VBScript, but I am trying to figure it out. When I run the script I get the following error.
Script: c:\temp\mail.vbs
Line: 43
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error
When I edit my script and goto line 43, I find the following command.
Set fso = CreateObject ("Scripting.FileSystemObject"
I don't see anything wrong with this line, below is the entire script. Does anyone see what is wrong with this script? Thanks.
L_Welcome_MsgBox_Message_Text = "This searches for ORA- error messages in the alert log" & Chr(13) & "and creates a file named email.txt with the errors in it"
L_Welcome_MsgBox_Title_Text = "Alert log scan utility"
Call Welcome()
' ********************************************************************************
Dim WSHShell,sfile, dfile, fso, f, ts, sLine, sMail, redf, regEx, thisFolder, AllFiles
Set WSHShell = WScript.CreateObject("WScript.Shell"
sLine = "x"
n = 0
'------------------------------------------------
const pth = "./"
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
sfile = "c:\oracle\admin\DB1\bdump\db1ALRT.txt" ' Give the name of the file you want to search
dfile = "c:\oracle\admin\DB1\bdump\email.txt"
'-----------------------------------------------
Function RegExpMail(sLine)
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = "ORA-" ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(sLine) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & Match.Value
Next
RegExpMail = RetStr
End Function
' MsgBox(RegExpMail("is.", "IS1 is2 IS3 is4"
)
Set fso = CreateObject ("Scripting.FileSystemObject"
fso.CreateTextFile (dfile)
Set f = fso.GetFile(dfile)
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
'-----------------
Set fso = CreateObject ("Scripting.FileSystemObject"
Set redf = fs
penTextFile(sfile, ForReading)
'-----------------------------------
Do While redf.AtEndOfStream <> True
sLine = redf.ReadLine
sMail = (RegExpMail(sLine))
If sMail <> "" Then
ts.WriteLine (sMail)
End if
Loop
ts.Close
WScript.Echo "The work is done. Thanks!"
' ********************************************************************************
' *
' * Welcome
' *
Sub Welcome()
Dim intDoIt
intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
vbOKCancel + vbInformation, _
L_Welcome_MsgBox_Title_Text )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub
Set objEmail = CreateObject ("CDO.Message"
DateInfo = DateInfo & Now & VbCrLf
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set colSettings = objWMIService.ExecQuery ("Select * FROM Win32_ComputerSystem"
For each objSysInfo in colSettings
UserName = objSysinfo.UserName
Next
objEmail.From = "myserver1"
objEmail.To = "valid_email_address"
objEmail.Subject = "myserver1"
ObjEmail.Textbody = "...see alert log attached " & DateInfo
objEmail.Configuration.Fields.Item (" = 2
objEmail.Configuration.Fields.Item (" = "valid IP"
objEmail.Configuration.Fields.Item (" = 25
objEmail.Configuration.Fields.Update
objEmail.AddAttachment "c:\oracle\admin\DB1\bdump\email.txt"
objEmail.Send
Script: c:\temp\mail.vbs
Line: 43
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error
When I edit my script and goto line 43, I find the following command.
Set fso = CreateObject ("Scripting.FileSystemObject"
I don't see anything wrong with this line, below is the entire script. Does anyone see what is wrong with this script? Thanks.
L_Welcome_MsgBox_Message_Text = "This searches for ORA- error messages in the alert log" & Chr(13) & "and creates a file named email.txt with the errors in it"
L_Welcome_MsgBox_Title_Text = "Alert log scan utility"
Call Welcome()
' ********************************************************************************
Dim WSHShell,sfile, dfile, fso, f, ts, sLine, sMail, redf, regEx, thisFolder, AllFiles
Set WSHShell = WScript.CreateObject("WScript.Shell"
sLine = "x"
n = 0
'------------------------------------------------
const pth = "./"
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
sfile = "c:\oracle\admin\DB1\bdump\db1ALRT.txt" ' Give the name of the file you want to search
dfile = "c:\oracle\admin\DB1\bdump\email.txt"
'-----------------------------------------------
Function RegExpMail(sLine)
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = "ORA-" ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(sLine) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & Match.Value
Next
RegExpMail = RetStr
End Function
' MsgBox(RegExpMail("is.", "IS1 is2 IS3 is4"
Set fso = CreateObject ("Scripting.FileSystemObject"
fso.CreateTextFile (dfile)
Set f = fso.GetFile(dfile)
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
'-----------------
Set fso = CreateObject ("Scripting.FileSystemObject"
Set redf = fs
'-----------------------------------
Do While redf.AtEndOfStream <> True
sLine = redf.ReadLine
sMail = (RegExpMail(sLine))
If sMail <> "" Then
ts.WriteLine (sMail)
End if
Loop
ts.Close
WScript.Echo "The work is done. Thanks!"
' ********************************************************************************
' *
' * Welcome
' *
Sub Welcome()
Dim intDoIt
intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
vbOKCancel + vbInformation, _
L_Welcome_MsgBox_Title_Text )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub
Set objEmail = CreateObject ("CDO.Message"
DateInfo = DateInfo & Now & VbCrLf
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set colSettings = objWMIService.ExecQuery ("Select * FROM Win32_ComputerSystem"
For each objSysInfo in colSettings
UserName = objSysinfo.UserName
Next
objEmail.From = "myserver1"
objEmail.To = "valid_email_address"
objEmail.Subject = "myserver1"
ObjEmail.Textbody = "...see alert log attached " & DateInfo
objEmail.Configuration.Fields.Item (" = 2
objEmail.Configuration.Fields.Item (" = "valid IP"
objEmail.Configuration.Fields.Item (" = 25
objEmail.Configuration.Fields.Update
objEmail.AddAttachment "c:\oracle\admin\DB1\bdump\email.txt"
objEmail.Send