?
Solved

vbs script extract data from logs within last 24 hours

Posted on 2014-03-15
3
Medium Priority
?
517 Views
Last Modified: 2014-03-16
folks

how can I extract specific data from other logs into another log file but only after a specific timestamplis met i.e. i want to extract the values


"system#notboundexception" Or  "Successfully connected" from log 1 and log 2 but only if they are logged within the last 24 hours from now
log 1

[14/03/14 16:04:51:985 GMT xxxxxxxxxxxx eeeeeeeeeeeeeee
system#notboundexception

[15/03/14 10:04:51:985 GMT xxxxxxxxxxxx eeeeeeeeeeeeeee
system#notboundexception


log 1

[12/03/14 16:24:51:985 GMT xxxxxxxxxxxx eeeeeeeeeeeeeee
system#notboundexception

[15/03/14 10:04:51:985 GMT xxxxxxxxxxxx eeeeeeeeeeeeeee
Successfully connected

output.log should only show the log entries from either log 1 /2 on over the last 24 hours (being today)

how can I achieve this?

Below is my code to  extract the values from the logs , I need help in assuring only todays records are extracted only


Dim objFSO
Dim objFile
Dim objOut
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
 
 'create output file
 strOutputName = "output.txt"
 Set objOut = objFSO.GetFolder(strFolder).CreateTextFile(strOutputName, True)
 

'for each file in directory
For Each objFile In objFSO.GetFolder(strFolder).Files
        'if its a log file
        If Right(LCase(objFile.Name), 4) = ".log" Then
               'open log file
                Set objLogFile = objFSO.OpenTextFile(objFile.Path, intForReading, False)
                'loop thorugh log file
                Do While Not objLogFile.AtEndOfStream
                        strData = Replace(objLogFile.ReadLine, ",", "")
                        'replace(var,",","")
                        If InStr(strData, "system#notboundexception") Or InStr(strData, "Successfully connected") Then objOut.WriteLine strData & ", " & objFile.Name & ", " & Date & ", " & Time & ""
                Loop

                objLogFile.Close
                Set objLogFile = Nothing
       
        End If
Next
objOut.Close


all help will do
0
Comment
Question by:rutgermons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

Expert Comment

by:Kimputer
ID: 39932009
In your final check before writing the result:

 If InStr(strData, "system#notboundexception") Or InStr(strData, "Successfully connected") Then objOut.WriteLine strData & ", " & objFile.Name & ", " & Date & ", " & Time & ""

add an extra test for date as in:

if (cdate(mid(strData,2,17)) > DateAdd("d", -1, Now)) then
0
 

Author Comment

by:rutgermons
ID: 39932302
Kimputer

Could you show me where this exactly fits in the code?

thanks in advance!
0
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 39932603
Sorry, I thought you did the original code, so I thought you could fit it in yourself. But here's the full code:

Dim objFSO
Dim objFile
Dim objOut
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
 
 'create output file
 strOutputName = "output.txt"
 Set objOut = objFSO.GetFolder(strFolder).CreateTextFile(strOutputName, True)
 

'for each file in directory
For Each objFile In objFSO.GetFolder(strFolder).Files
        'if its a log file
        If Right(LCase(objFile.Name), 4) = ".log" Then
               'open log file
                Set objLogFile = objFSO.OpenTextFile(objFile.Path, intForReading, False)
                'loop thorugh log file
                Do While Not objLogFile.AtEndOfStream
                        strData = Replace(objLogFile.ReadLine, ",", "")
                        'replace(var,",","")
                        If InStr(strData, "system#notboundexception") Or InStr(strData, "Successfully connected") Then
							if (cdate(mid(strData,2,17)) > DateAdd("d", -1, Now)) then
								objOut.WriteLine strData & ", " & objFile.Name & ", " & Date & ", " & Time & ""
							end if
						end if 
                Loop

                objLogFile.Close
                Set objLogFile = Nothing
       
        End If
Next
objOut.Close

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question