Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On 13 helmi, 22:16, "McKirahan" <N...@xxxxxxxxxxxxx> wrote:
"Tomi" <tomi.har...@xxxxxxxxx> wrote in message

news:1ed7dc85-6677-4f54-ba5b-3d7c5bae7123@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 13 helmi, 20:07, "McKirahan" <N...@xxxxxxxxxxxxx> wrote:





<tomi.har...@xxxxxxxxx> wrote in message

news:f5b6cccd-1664-480a-9f07-0c7db65c1d40@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I´m really neube on this and please help me with this.

So I need script that search from c:\temp1\testi1.txt file lines that
have word ERROR or WARN.
If the script found any lines that contain those it will send those
lines via email.
I know that this is very easy for you, but I´m having big problems
with this,
Here is my script what I´m working (And yes I know that it´s not
good) :)
Could you please help me with this.

You seem pretty close. Try changing this line:

if instr(strLine,"ERROR") or instr(strLine,"WARN") then

to these two lines:

If InStr(strLine,"ERROR") > 0 _
Or InStr(strLine,"WARN") > 0 Then

Unless you're sure the words you are seareching for a
capitaized you might want to add this line:

strLine = UCase(strLine)
Ok, thanks for that.

You're welcome.

Yes, those words which I´m searching are capital, did you mean that?
Where should I put Line strLine = Ucase(strLine)?

You don't need to add it if you know that they're always capitalized.
If they're not the this line
    strLine=fRead.ReadLine
could be changed to
     strLine = UCase(fRead.ReadLine)

Other problem what I have with this I don´t know how to send those
error line with this script.  So the problem is I have two different
script 1. find those lines which have ERROR or WARN  2. Send email to
address. I don´t know how put those ERROR and WARN lines to email if
found? How I creat this one working script?

[snip]

Do you want one email sent for all lines found or one email for each line?

If you want all lines in a single email then after the loop add this line:
    Call sendmail(data)

and change
    Function sendmail
to
    Sub sendmail(data)

and change
    End Function
to
    End sub

and change
        .TextBody = "This is a test for CDO.message"
to
        .TextBody = data- Piilota siteerattu teksti -

- Näytä siteerattu teksti -



Hi,

Thanks a lot again!

I changed scirpt as you tould so, but now the problem is that when I
get email, text body is empty. And yes I want all lines in single
mail. testi1.txt file contain 4 different line:

fkalöjfkldaö
jfkdaljfkladöjfldöa
ERROR haloo ajf haloo klaöjfalök
WARN haloo

So If script works fine I should have mail where text body is:
ERROR haloo ajf haloo klaöjfalök
WARN haloo

Is there still something wrong?
Big Thanks you McKirahan











set fso=CreateObject("Scripting.FileSystemObject")
set fRead =fso.OpenTextFile("c:\temp1\testi1.txt",1)

Do While fRead.AtEndOfStream <> True
strLine=fRead.ReadLine
If InStr(strLine,"ERROR") > 0 _
Or InStr(strLine,"WARN") > 0 Then
strMail=strMail & strLine & vbcrlf
end if
loop
call sendmail(data)
set fRead=nothing
set fso=nothing

Sub sendmail(data)
sch = "http://schemas.microsoft.com/cdo/configuration/";

Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "81.228.8.17"
.update
End With

Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
Set .Configuration = cdoConfig
.From = "from@xxxxxx"
.To = "tomi.harman@xxxxxxxxx"
.Subject = "Sample CDO Message"
.TextBody = data
.Send
End with

Set cdoMessage = Nothing
Set cdoConfig = Nothing
end sub
.



Relevant Pages

  • Re: scripting newb
    ... I was able to hobble this together from another script posted by Dan ... Dim strSearch, strAdsPath, strServerName 'from search script ...     'Prompt for search criteria ... computerName, samAccountName, givenName, sn, AdsPath ...
    (microsoft.public.scripting.vbscript)
  • Re: finding files
    ... I'm back and also my script as changed ever since. ... have to be an Array then.. ... For Each strComputer In arrComputers ...     Function ReadTxtToArray ...
    (microsoft.public.scripting.vbscript)
  • Re: 2 scripts w errors on compacting access db
    ... Script 1: ... This old newsgroup thread included code to compact an Access database: ... ' You must provide a path to the Access MDB which will be compacted ...     On Error GoTo 0 ...
    (microsoft.public.scripting.vbscript)
  • Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
    ... script is reaching out to a SQLServer database and grabbing some data ... BinaryStream.Write method expects a byte array, ...     Else ... I made the changes to the script using your code, ...
    (microsoft.public.scripting.vbscript)
  • Re: Webster van Robot help
    ...   Line: 19 ... Is the line number relative to the <script> statement? ... There is no such thing as associative arrays in JavaScript. ... table {border-collapse: collapse;} ...
    (comp.lang.javascript)