Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- From: "McKirahan" <News@xxxxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 14:51:40 -0600
"Tomi" <tomi.harman@xxxxxxxxx> wrote in message
news:88eaa40d-fd30-49b4-a431-f2fafe5fe37c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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
[snip]
Sorry, this line
call sendmail(data)
should be
call sendmail(strMail)
If you're interested, below is am untested rewrite of your code:
Option Explicit
'*
'* Declare Constants
'*
Const cTXT = "c:\temp1\testi1.txt"
Const cCDO = "http://schemas.microsoft.com/cdo/configuration/"
Const cSUB = "ERROR or WARN lines!"
'*
'* Declare Variables
'*
Dim intCDO
intCDO = 0
Dim strCDO
Dim strOTF
'*
'* Declare Objects
'*
Dim objCDO
Dim objFSO
Dim objOTF
'*
'* Read file
'*
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set obtOTF = objFSO.OpenTextFile(cTXT,1)
Do While Not objOTF.AtEndOfStream
strOTF = objOTF.ReadLine
If InStr(strOTF,"ERROR") > 0 _
Or InStr(strOTF,"WARN") > 0 Then
intCDO = intCDO + 1
strCDO = strCDO & vbCrLf & strOTF
End If
Loop
Set objOTF = Nothing
Set objFSO = Nothing
'*
'* Send Email without Installing the SMTP Service
'*
http://www.microsoft.com/technet/scriptcenter/scripts/message/smtpmail/mssmv
b02.mspx
'*
Set objCDO = CreateObject("CDO.Message")
objCDO.From = "from@xxxxxx"
objCDO.To = "tomi.harman@xxxxxxxxx"
objCDO.Subject = cSUB
objCDO.TextBody = intCDO & " " & cSUB & vbCrLf & strCDO
objCDO.Configuration.Fields.Item(cCDO & "sendusing") = 2
objCDO.Configuration.Fields.Item(cCDO & "smtpserver") =
"81.228.8.17"
objCDO.Configuration.Fields.Item(cCDO & "smtpserverport") = 25
objCDO.Configuration.Fields.Update
objCDO.Send
Set objCDO = Nothing
'*
'* Destroy Objects
'*
'*
MsgBox intCDO & " " & cSUB,vbInformation,WScript.ScriptName
.
- 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
- Re: Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- From: Tomi
- Script to search from txt file lines that contain ERROR or WARN and if found them send it to mail
- Prev by Date: Re: Import and Insert data from email
- 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
|