Bat file scripting parsing log entries by date/time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
playforkeeps
Posts: 1
Joined: 06 Aug 2013 09:23

Bat file scripting parsing log entries by date/time

#1 Post by playforkeeps » 06 Aug 2013 09:39

Hi All :D

Can anyone help me with this please.

I am using the following bat file code to search through an IIS log file a return the total count of GET requests.

Code: Select all

@ECHO OFF
SET logfolder=\\127.0.0.1\c$\WINDOWS\system32\LogFiles\W3SVC1
SET /a counter=0

:: get newest file
FOR /F  %%f IN ('DIR %logfolder% /B /O:D') DO SET newestfile=%%f

:: copy newest file to temp file
COPY "%logfolder%\%newestfile%" c:\temp\xx.log > NUL

:: process each line in the file
FOR /F "usebackq delims=" %%l in (c:\temp\xx.log) DO (
  FOR /F "tokens=7 delims= " %%a in ("%%l") DO (
     IF %%a == GET SET /a counter+=1
   )
)

:: output to console
ECHO %counter%:Ok

:: delete temp file
DEL c:\temp\xx.log > NUL


Now I only want a return count of GET request that happened within the previous 5 minutes. So somehow in this batch file i need
to get the current system date and time. Minus 5 minutes and then count values in between these times.


2013-07-24 23:59:59
Return all GET request in between
2013-07-24 23:54:59

Thanks for any help.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Bat file scripting parsing log entries by date/time

#2 Post by penpen » 06 Aug 2013 14:01

As i have no Microsoft Internet Information Services/Server by hand, i need some test case sample log file lines with the needed information.
And i assume i am not alone with that problem, although i don't know it.

penpen

Post Reply