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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange error message

Status
Not open for further replies.

vbcdor

Technical User
Jan 27, 2004
39
US
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 = fso_OpenTextFile(sfile, ForReading)
'-----------------------------------


Do While redf.AtEndOfStream <> True
sLine = redf.ReadLine
sMail = (RegExpMail(sLine))
If sMail <> &quot;&quot; Then

ts.WriteLine (sMail)

End if




Loop
ts.Close

WScript.Echo &quot;The work is done. Thanks!&quot;


' ********************************************************************************
' *
' * 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 (&quot;CDO.Message&quot;)
DateInfo = DateInfo & Now & VbCrLf
StrComputer = &quot;.&quot;
Set objWMIService = GetObject (&quot;winmgmts:&quot; & &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colSettings = objWMIService.ExecQuery (&quot;Select * FROM Win32_ComputerSystem&quot;)
For each objSysInfo in colSettings
UserName = objSysinfo.UserName
Next
objEmail.From = &quot;myserver1&quot;
objEmail.To = &quot;valid_email_address&quot;
objEmail.Subject = &quot;myserver1&quot;
ObjEmail.Textbody = &quot;...see alert log attached &quot; & DateInfo
objEmail.Configuration.Fields.Item (&quot; = 2
objEmail.Configuration.Fields.Item (&quot; = &quot;valid IP&quot;
objEmail.Configuration.Fields.Item (&quot; = 25
objEmail.Configuration.Fields.Update
objEmail.AddAttachment &quot;c:\oracle\admin\DB1\bdump\email.txt&quot;
objEmail.Send
 
Does &quot;c:\oracle\admin\DB1\bdump\db1ALRT.txt&quot; allways exists ?

Hope This Help
PH.
 
PHV,
Yes, c:\oracle\admin\DB1\bdump\db1ALRT.txt always exists.

 
how many references to a filesystem object do you need?

why the WMI call towards the end??
 
Have you tried this, to be sure ?
WScript.Echo sfile & vbCrLf & fso.FileExists(sfile)
Anyway, in your script fso is already instantiated, so no need of the CreateObject on line 42.

Hope This Help
PH.
 
Hello vbcdor,

Try modify the corresponding part:
Code:
'...
  Set fso = CreateObject (&quot;Scripting.FileSystemObject&quot;)
  Set f = fso.CreateTextFile (dfile, True)
  f.close
  Set f = fso.GetFile(dfile)
  Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)

'-----------------

'Set fso = CreateObject (&quot;Scripting.FileSystemObject&quot;)
Set redf = fso.OpenTextFile(sfile, ForReading)
'-----------------------------------


Do While redf.AtEndOfStream <> True
sLine = redf.ReadLine
sMail = (RegExpMail(sLine))
 If sMail <> &quot;&quot; Then 

ts.WriteLine sMail

 End if




Loop
  ts.Close
  redf.Close
'...
regards - tsuji
 
phv,
I removed the 2nd fso and I put in the WScript.Echo statement and it came up false. I don't get it, it appears to be there. It even displays correctly in the WScript.Echo command.



 
No vbCrLf or alike in sfile ? Try this:
Code:
WScript.Echo &quot;'&quot; & sfile & &quot;'&quot;
and pay attention to the single quotes to see if sfile is correctly spelled, without garbage char.

Hope This Help
PH.
 
PHV,

After doing this I still don not see the difference. Can I email you a screen print of the file location and the error message?

vbcdor
 
Launch your script with cscript in a console window, then do a dir of sfile in the same command line session.
Copy/paste the screen contents and post it.
 
PHV, here it is:



Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>cscript c:\temp\mail.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

c:\temp\mail.vbs(44, 1) Microsoft VBScript runtime error: File not found


C:\>dir c:\oracle\admin\DB1\bdump
Volume in drive C has no label.
Volume Serial Number is E824-BFA9

Directory of c:\oracle\admin\DB1\bdump

01/28/2004 08:02a <DIR> .
01/28/2004 08:02a <DIR> ..
01/30/2004 09:09a 1,471,832 db1ALRT.LOG
01/27/2004 02:20p 1,459,101 db1alrt.log2
09/16/2003 12:51p 31,842 db1ARC0.TRC
09/16/2003 12:53p 440,141 db1DBW0.TRC
06/04/2003 06:46a 785 db1SNP0.TRC
06/04/2003 06:46a 784 db1SNP1.TRC
06/04/2003 06:46a 1,573 db1SNP2.TRC
06/04/2003 06:46a 786 db1SNP3.TRC
01/30/2004 10:35a 0 email.txt
9 File(s) 3,406,844 bytes
2 Dir(s) 3,127,443,456 bytes free

C:\>
 
just an additional note, I changed the script to sfile=&quot;c:\oracle\admin\DB1\bdump\db1ALRT.LOG&quot; and I get the above error.
 
I don't see on your screen dump the WScript.Echo of sfile surrounded by single quotes.
 
PHV,

Please ignore above posts. I found the problem, I had changed the sfile variable into a hard coded file later in the script. Thanks for you help.

vbcdor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top