Hi all, I need to write a vbscript to search a string value in a text log
file. If the string value is present, it will send an email. I know the
script for sending the email.

Please someone help me for searching a log file.

Re: script for searching a string in a log file by papou

papou
Wed May 16 07:44:43 CDT 2007

Hi Sekhar
Here's one way, please amend accordingly.
HTH
Cordially
Pascal

'Reading = 1, Writing = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\valeursexcel.txt", 1)
Dim SearchString
SearchString = "texte test"
Dim LineToRead
Dim Found
Do while MyFile.AtEndOfStream <> True
LineToRead = MyFile.ReadLine
If Instr(1, LineToRead, SearchString) <> 0 Then
'String is found
Found = True
Exit Do
Else
Found = False
End If
Loop

Dim Msg
Select Case Found
Case True
strMsg = " was found"
'Do Something else here
Case Else
StrMsg = " was not found"
End select

WScript.Echo SearchString & StrMsg


"sekhar" <sekhar@discussions.microsoft.com> a écrit dans le message de news:
6945CDEA-05AB-4063-9895-86874C74BF26@microsoft.com...
> Hi all, I need to write a vbscript to search a string value in a text log
> file. If the string value is present, it will send an email. I know the
> script for sending the email.
>
> Please someone help me for searching a log file.



Re: script for searching a string in a log file by Ayush

Ayush
Wed May 16 13:49:35 CDT 2007

[sekhar]s message :
> Hi all, I need to write a vbscript to search a string value in a text log
> file. If the string value is present, it will send an email. I know the
> script for sending the email.

> Please someone help me for searching a log file.

file="filepath"
search="xxx"

Set fs = CreateObject("Scripting.FileSystemObject")
Set filestr = fs.OpenTextFile(file, 1)
If InStr(filestr.ReadAll,search) Then msgbox "Found"
filestr.Close()


Good Luck, Ayush.
--
Scripting Home : http://snipurl.com/Scripting_Home

Re: script for searching a string in a log file by akkha1234

akkha1234
Wed May 16 18:39:59 CDT 2007

On May 16, 5:44 am, "papou" <cestpasbon@=E7anonplus44.fr> wrote:
> Hi Sekhar
> Here's one way, please amend accordingly.
> HTH
> Cordially
> Pascal
>
> 'Reading =3D 1, Writing =3D 2
> Dim fso, MyFile
> Set fso =3D CreateObject("Scripting.FileSystemObject")
> Set MyFile =3D fso.OpenTextFile("c:\valeursexcel.txt", 1)
> Dim SearchString
> SearchString =3D "texte test"
> Dim LineToRead
> Dim Found
> Do while MyFile.AtEndOfStream <> True
> LineToRead =3D MyFile.ReadLine
> If Instr(1, LineToRead, SearchString) <> 0 Then
> 'String is found
> Found =3D True
> Exit Do
> Else
> Found =3D False
> End If
> Loop
>
> Dim Msg
> Select Case Found
> Case True
> strMsg =3D " was found"
> 'Do Something else here
> Case Else
> StrMsg =3D " was not found"
> End select
>
> WScript.Echo SearchString & StrMsg
>
> "sekhar" <sek...@discussions.microsoft.com> a =E9crit dans le message de =
news:
> 6945CDEA-05AB-4063-9895-86874C74B...@microsoft.com...
>
> > Hi all, I need to write a vbscript to search a string value in a text l=
og
> > file. If the string value is present, it will send an email. I know the
> > script for sending the email.
>
> > Please someone help me for searching a log file.

In the compare line, you might want to use (1,LineToRead, SearchString,
1) if you do not want case sensitive comparison.


Re: script for searching a string in a log file by sekhar

sekhar
Thu May 17 06:35:01 CDT 2007

Thank you very much for a good cool script.

"Ayush" <"ayushmaan.j[aatt]gmail.com" wrote:

> [sekhar]s message :
> > Hi all, I need to write a vbscript to search a string value in a text log
> > file. If the string value is present, it will send an email. I know the
> > script for sending the email.
>
> > Please someone help me for searching a log file.
>
> file="filepath"
> search="xxx"
>
> Set fs = CreateObject("Scripting.FileSystemObject")
> Set filestr = fs.OpenTextFile(file, 1)
> If InStr(filestr.ReadAll,search) Then msgbox "Found"
> filestr.Close()
>
>
> Good Luck, Ayush.
> --
> Scripting Home : http://snipurl.com/Scripting_Home
>

Re: script for searching a string in a log file by sekhar

sekhar
Thu May 17 06:38:01 CDT 2007

Thanks for giving the prompt response. But ayush has given a cool small
script which helped me a lot. The script i wanted to write is as follows:

file="text file path"
search="string"

Set fs = CreateObject("Scripting.FileSystemObject")
Set filestr = fs.OpenTextFile(file, 1)
If InStr(filestr.ReadAll,search) Then call sendmail
filestr.Close()

Function sendmail
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "sender mail id"
objEmail.To = "receiver mail id"
objEmail.Subject = "subject of the message"
objEmail.Textbody = "Body of the message"
objEmail.Send
End Function

Thank you all.

"akkha1234@gmail.com" wrote:

> On May 16, 5:44 am, "papou" <cestpasbon@çanonplus44.fr> wrote:
> > Hi Sekhar
> > Here's one way, please amend accordingly.
> > HTH
> > Cordially
> > Pascal
> >
> > 'Reading = 1, Writing = 2
> > Dim fso, MyFile
> > Set fso = CreateObject("Scripting.FileSystemObject")
> > Set MyFile = fso.OpenTextFile("c:\valeursexcel.txt", 1)
> > Dim SearchString
> > SearchString = "texte test"
> > Dim LineToRead
> > Dim Found
> > Do while MyFile.AtEndOfStream <> True
> > LineToRead = MyFile.ReadLine
> > If Instr(1, LineToRead, SearchString) <> 0 Then
> > 'String is found
> > Found = True
> > Exit Do
> > Else
> > Found = False
> > End If
> > Loop
> >
> > Dim Msg
> > Select Case Found
> > Case True
> > strMsg = " was found"
> > 'Do Something else here
> > Case Else
> > StrMsg = " was not found"
> > End select
> >
> > WScript.Echo SearchString & StrMsg
> >
> > "sekhar" <sek...@discussions.microsoft.com> a écrit dans le message de news:
> > 6945CDEA-05AB-4063-9895-86874C74B...@microsoft.com...
> >
> > > Hi all, I need to write a vbscript to search a string value in a text log
> > > file. If the string value is present, it will send an email. I know the
> > > script for sending the email.
> >
> > > Please someone help me for searching a log file.
>
> In the compare line, you might want to use (1,LineToRead, SearchString,
> 1) if you do not want case sensitive comparison.
>
>

Re: script for searching a string in a log file by Ayush

Ayush
Thu May 17 17:14:01 CDT 2007

[sekhar]s message :
> Thank you very much for a good cool script.

You're welcome !

Good Luck, Ayush.
--
Script Center-Script Repository : http://snipurl.com/Script_Repository

Re: script for searching a string in a log file by haroon

haroon
Tue May 22 15:47:26 CDT 2007

On May 17, 6:14 pm, Ayush <"ayushmaan.j[aatt]gmail.com"> wrote:
> [sekhar]s message :
>
> > Thank you very much for a good cool script.
>
> You're welcome !
>
> Good Luck, Ayush.
> --
> Script Center-Script Repository :http://snipurl.com/Script_Repository

I need a script that can extract certain line of txt from a file. Or
script that can look for a string and then extract the next 1 or 2
line after the String found in that file.
Please help.


Re: script for searching a string in a log file by Ayush

Ayush
Tue May 22 16:48:25 CDT 2007

[haroon.hazara@gmail.com]s message :
> I need a script that can extract certain line of txt from a file.

file="C:\documents and settings\Ayush\Desktop\test.txt"
line=3

Set fs = CreateObject("Scripting.FileSystemObject")
Set filestr = fs.OpenTextFile(file, 1)
line=split(filestr.ReadAll,vbCrLf)(line-1)
filestr.Close()
msgbox line



Good Luck, Ayush.
--
Regular Expression Syntax : http://snipurl.com/RegularExpr_Syntax