Hi!
I have a text file with the following entries:
p5872 rdp-tcp#1 2 Aktiv . 29.11.2012 10:08
p5871 rdp-tcp#1 2 Aktiv . 29.11.2012 11:08
p5870 rdp-tcp#1 2 Aktiv . 29.11.2012 12:08
p5869 rdp-tcp#1 2 Aktiv . 29.11.2012 13:08
p5868 rdp-tcp#1 2 Aktiv . 29.11.2012 14:08
I would like to count the number of entries with the string 'rdp-tcp' and send an alert to an email adress every hour.
Is this possible?
Thank you!
Regards
Christian
Number of entries in a textfile
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
In some cases you may use Text Log test for this purpose.
Could you please give more information:
1. File name is static or dynamic (new day - new file, e.g. 2012-11-29.txt) ?
2. Do you want to count new/added specific records (lines), or count specific records(lines) in entire file ?
or, maybe you want to get alert when records count is less or more then expected ?
Could you please give more information:
1. File name is static or dynamic (new day - new file, e.g. 2012-11-29.txt) ?
2. Do you want to count new/added specific records (lines), or count specific records(lines) in entire file ?
Every hour ?I would like to count the number of entries with the string 'rdp-tcp' and send an alert to an email adress every hour.
or, maybe you want to get alert when records count is less or more then expected ?
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
This is a little bit confusing.The filename ... is newly created every 15 min. ...
I want to be informed about the number of entries every hour.
If file is created/overwriten every 15 minutes, how do you want do count records (every hour) in files (4 files per hour) that have been already overwritten ?
E.g.:
10:15 file.txt contain 12 Bad records
10:30 file.txt is overwritten and now contains 11 Bad records
10:45 file.txt is overwritten and now contains 6 Bad records
11:00 file.txt is overwritten and now contains 2 Bad records
HostMonitor can only detect 2 Bad records in last file.txt, because
3 previous files have been overwritten.
Or maybe I haven't understood you correctly ?
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
If you need just count lines that contains some text in entire file, you may use Shell Script test with custom made script.
E.g. Script may look like the following:
Start CMD: cmd /c cscript /B /E:VBScript %Script% %Params%
This script requires 2 or 3 parameters: <file path> <text to search> [<max count>].
Please note, if you are using file path or search text that contain spaces, you should quote them.
e.g. Script parameters may look like the following:
"C:\Program Files(x86)\Logs\log.txt" rdp-tcp 20
E.g. Script may look like the following:
Code: Select all
Option Explicit
On Error Resume Next
const statusUnknown = "scriptRes:Unknown:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
dim objArgs, FileName, Find, objFSO, objTextFile, cnt, strtext, MaxCount
Set objArgs = WScript.Arguments
IF objArgs.Count < 2 Then
WScript.StdOut.Write statusUnknown & "Expected parameters: <file path> <text to search> [<max count>]"
Wscript.Quit
End if
FileName = objArgs(0)
Find = objArgs(1)
If objArgs.Count > 2 Then
MaxCount = objArgs(2)
Else
MaxCount = -1
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(FileName)=False then
WScript.StdOut.Write statusUnknown & "File not found: " & FileName
WScript.Quit
End if
Set objTextFile = objFSO.OpenTextFile(FileName, 1)
cnt=0
Do While (objTextFile.AtEndOfStream <> True)
strtext = objTextFile.ReadLine
if InStr(1, strtext, Find,0) Then
cnt=cnt+1
End If
Loop
if (cnt > int(MaxCount)) AND (MaxCount <> -1) then
WScript.StdOut.Write statusBad & cnt
Else
WScript.StdOut.Write statusOk & cnt
End if
This script requires 2 or 3 parameters: <file path> <text to search> [<max count>].
Please note, if you are using file path or search text that contain spaces, you should quote them.
e.g. Script parameters may look like the following:
"C:\Program Files(x86)\Logs\log.txt" rdp-tcp 20
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact: