Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- From: Tomi <tomi.harman@xxxxxxxxx>
- Date: Wed, 13 Feb 2008 12:44:08 -0800 (PST)
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
.
- Follow-Ups:
- References:
- Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- From: tomi . harman
- Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- From: McKirahan
- Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- From: Tomi
- Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- From: McKirahan
- Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- Prev by Date: Re: Does Open File For Output As #1 work in VBS?
- Next by Date: Re: Import and Insert data from email
- Previous by thread: Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- Next by thread: Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- Index(es):
Relevant Pages
|