Build Some Automatic Report

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Build Some Automatic Report

#1 Post by darioit » 29 Sep 2010 07:27

Hello Everybody,

each minute I produce this log file:
Heap_summary_information_2010-09-29-15.09.00.LOG
Heap_summary_information_2010-09-29-15.10.00.LOG
Heap_summary_information_2010-09-29-15.11.00.LOG
.................................

With inside this information:


Desktop Heap Information Monitor Tool (Version 8.1.2925.0)
Copyright (c) Microsoft Corporation. All rights reserved.
-------------------------------------------------------------
Session ID: 0 Total Desktop: ( 7360 KB - 11 desktops)

WinStation\Desktop Heap Size(KB) Used Rate(%)
-------------------------------------------------------------
WinSta0\Default 3072 4.1
WinSta0\Disconnect 64 4.0
WinSta0\Winlogon 128 9.7
Service-0x0-3e7$\Default 512 13.7
Service-0x0-3e4$\Default 512 1.8
Service-0x0-3e5$\Default 512 0.5
SAWinSta\SADesktop 512 0.5
__X78B95_89_IW\__A8D9S1_42_ID 512 0.4
Service-0x0-13280$\Default 512 1.4
Service-0x0-2f18567$\Default 512 1.3
Service-0x0-18b601$\Default 512 1.9
-------------------------------------------------------------


My goal is to build some report, 1 time at day, that read each row, and create multiple file like this

File 1:
WinSta0_Default_2010-09-29.txt
that contains:
Heap_summary_information_2010-09-29-15.09.00 WinSta0\Default 4.1
Heap_summary_information_2010-09-29-15.10.00 WinSta0\Default 4.1
Heap_summary_information_2010-09-29-15.11.00 WinSta0\Default 4.1

File 2:
WinSta0_Disconnect_2010-09-29.txt
that contains:
Heap_summary_information_2010-09-29-15.09.00 WinSta0\Disconnect 4.0
Heap_summary_information_2010-09-29-15.10.00 WinSta0\Disconnect 4.0
Heap_summary_information_2010-09-29-15.11.00 WinSta0\Disconnect 4.0

......


FILE n:
Service-0x0-18b601$_2010-09-29.txt
that contains:
Heap_summary_information_2010-09-29-15.09.00 Service-0x0-3e7$\Default 1.9
Heap_summary_information_2010-09-29-15.10.00 Service-0x0-3e7$\Default 1.9
Heap_summary_information_2010-09-29-15.11.00 Service-0x0-3e7$\Default 1.9

The word Default can be omitted
It's possible to do this work with a script?

Regards
Dario

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Build Some Automatic Report

#2 Post by aGerman » 29 Sep 2010 13:54

Unfortunately you didn't use code tags. Looks like the 8th line of the .log file is the first line you want to create a new file.
Try this

Code: Select all

@echo off &setlocal
for %%a in (Heap_summary_information_*.LOG) do (
  for /f "tokens=1* delims=:" %%b in ('findstr /n . "%%~a"') do (
    if %%b geq 8 (
      if %%b leq 18 (
        for /f "tokens=4-6 delims=_-" %%d in ("%%~na") do (
          for /f "tokens=1,3" %%g in ("%%c") do (
            for /f "tokens=1* delims=\" %%j in ("%%g") do (
              >>%%j_%%k_%%d-%%e-%%f.txt echo %%~na %%g %%h
            )
          )
        )
      )
    )
  ) 
)


Regards
aGerman

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Build Some Automatic Report

#3 Post by amel27 » 29 Sep 2010 18:15

Code: Select all

@echo off
setlocal EnableDelayedExpansion

for %%i in (Heap_summary_information_*.LOG) do (
  set "$i=%%~ni"& set "$t=!$i:~-19!"& set "$d=!$t:~,10!"
  for /f "tokens=1-4 delims=\ " %%j in ('findstr /rc:"\.[0-9][0-9]*$" "%%i"') do (
    >>"%%j_%%k_!$d!.txt" echo.!$i! %%j\%%k %%m
))

You can filter processed files by date via mask: "Heap_summary_information_2010-09-29*.LOG"

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Build Some Automatic Report

#4 Post by alan_b » 01 Oct 2010 03:39

Instead of filtering a few hundred files at one time,
it may be feasible to copy/concatenate each log into a master file,
and then once a day filter only the master file instead of a few hundred mini log files.

The potential benefit is that the filtered output CANNOT get the events in the wrong date/time order.

I plead fear and ignorance here, but I am uncertain upon the order of file selection via

Code: Select all

for %%i in (Heap_summary_information_*.LOG) do (lots of code)

I look forward to expert comments upon my fear

Regards
Alan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Build Some Automatic Report

#5 Post by aGerman » 01 Oct 2010 14:38

alan_b wrote:I plead fear and ignorance here, but I am uncertain upon the order of file selection via

Code: Select all

for %%i in (Heap_summary_information_*.LOG) do (lots of code)

I look forward to expert comments upon my fear

Regards
Alan


Hello Alan.

The order of file selection depends on the file system of the volume.
NTFS formatted volumes support sorting directory entries. That means the for loop returns the files in ascending order by names.
On FAT or FAT32 formatted volumes the for loop would return the files in the order they were added to the directory.

How ever, both would work for darioit's intention :wink:
Otherwise you could process the output of DIR with suitable options to make sure...

Regards
aGerman

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Build Some Automatic Report

#6 Post by alan_b » 02 Oct 2010 01:37

aGerman wrote:Hello Alan.

The order of file selection depends on the file system of the volume.
NTFS formatted volumes support sorting directory entries. That means the for loop returns the files in ascending order by names.
On FAT or FAT32 formatted volumes the for loop would return the files in the order they were added to the directory.

Regards
aGerman

I now understand why I was unsure - I have had conflicting experiences.
Although I have XP in NTFS formatted C:\, I also have data partitions formatted as FAT32.

Thanks for explanation.
Alan

Post Reply