Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


search a text file and send email based on string

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59713
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> search a text file and send email based on string
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 search a text file and send email based on string - 5/1/2008 2:07:54 AM   
  NewBee

 

Posts: 32
Score: 0
Joined: 2/10/2006
Status: offline
I've done some search on this but not quite able to find out what i wanted.  sorry I'm not a vb export to do this on my own, that's why i need your help

what i want to do is search a text file from bottom to top for couple of strings such as "some string one","some string two" and "some string three"
If the script finds anyone of the strings it will send out and email and end its process.

your help is much appreciated

thanks
 
 
Post #: 1
 
 RE: search a text file and send email based on string - 5/1/2008 2:16:43 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
What have you written so far? Search for these terms to get yourself started:

FileSystemObject
OpenTextFile
Regular Expression
Regex
Regexp

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to NewBee)
 
 
Post #: 2
 
 RE: search a text file and send email based on string - 5/1/2008 4:19:59 AM   
  NewBee

 

Posts: 32
Score: 0
Joined: 2/10/2006
Status: offline
this is what i have so far, but i can not get it to search more then one string and it does not search the file from bottom to top.
also i like to have the serach to stop as soon as it finds one of the strings when doing the search from bottom to top.
Const ForReading = 1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True  
objRegEx.Pattern = "found what you are looking for - calls will not be collected"
also like to "include other strings" but it "gives me an error"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\temp\cdr1.log", ForReading)
strSearchString = objFile.ReadAll
objFile.Close

Set colMatches = objRegEx.Execute(strSearchString) 
If colMatches.Count > 0 Then
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "alert"
'objMessage.Sender = ""
objMessage.From = sender@company.com
objMessage.To = receiver@company.com
objMessage.TextBody = "check applicaton for failed process" i would like to include the String defined in objRegEx.Pattern here to give a better idea of the error if possible but not a priority
'objMessage.AddAttachment ""

'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"exchange ip address"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update

objMessage.Send
End If

 
I think this will do the search from bottom to top but i dont know where in the code should i include it, like i said before i have very limited knowledge when it comes to VB scripts.

Dim arrFileLines()
i = 0
Set objFSO
= CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\temp\cdr1.log", 6667)
Do
Until objFile.AtEndOfStream
Redim Preserve arrFileLines
(i)
arrFileLines(i) = objFile.ReadLine
i
= i + 1
Loop
objFile
.Close

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: search a text file and send email based on string - 5/1/2008 4:51:30 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Start small. Figure out how to get your matching working before you worry about the emailing. Here is an example of the matching that might help:

Option Explicit
'The test file contains this:
'Line 1
'Line 2
'This is the first part that we care about
'Line 4
'Line 5
'Another line that we want to Get
'Line 6
'Line 7
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim strFile : strFile = oFSO.OpenTextFile("C:\Temp\Test.txt").ReadAll()
Dim oRE : Set oRE = New RegExp
Dim colMatches
Dim oMatch
oRE.Global = True
oRE.Pattern = "(\n.*This is.*\n)|(\n.*Another.*\n)"
Set colMatches = oRE.Execute(strFile)
WScript.Echo colMatches.Count
For Each oMatch In colMatches
   WScript.Echo Replace(oMatch.Value, vbLf, "")
Next

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to NewBee)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> search a text file and send email based on string Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts