@ECHO OFF
REM THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
REM ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
REM THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
REM PARTICULAR PURPOSE.

REM Copyright (C) 2004 Microsoft Corporation.  All Rights Reserved.

REM ************************************************************************ 
REM ************************************************************************ 
REM MomBROFMON
REM 
REM This script is used to append individual BROFMON MOM rollup files into one BROFMON MOM log
REM 
REM Main tasks performed are 
REM      Find all BROFMON MOM rollup files in the central reporting directory
REM      Append their contents to the BROFMON MOM log file
REM      Delete the BROFMON MOM rollup files as they are appended
REM 
REM Usage 
REM      For usage information run MomBROFMON /? 
REM ************************************************************************ 
REM ************************************************************************ 

REM
REM Verify that there are two arguments present
REM

IF '%1' EQU '' GOTO ShowUsage
IF '%2' EQU '' GOTO ShowUsage

REM
REM Set Variables
REM

SETLOCAL
SET BROFMON_MOM_CLEAN_ONLY=false
SET BROFMON_MOM_LOG=
SET BROFMON_CENTRALREPORTINGDIR=%~1%


REM
REM Verify that Central Reporting Directory is available
REM

IF NOT EXIST "%BROFMON_CENTRALREPORTINGDIR%" (
   ECHO Central Reporting Directory "%BROFMON_CENTRALREPORTINGDIR% could not be reached.
   EXIT /B 201
)

REM
REM Determine if we are in Clean Only mode
REM

IF /I '%2' EQU '/CLEAN' (
   SET BROFMON_MOM_CLEAN_ONLY=true
) ELSE (
   SET BROFMON_MOM_LOG=%~2
)

REM
REM LOOP: Visit each BROFMON MOM rollup log file and append it to BROFMON MOM log
REM

 FOR /F "tokens=*" %%N IN ('DIR /B /S "%BROFMON_CENTRALREPORTINGDIR%\MOM*.rollup.log" 2^>^&1') DO (
   IF EXIST "%%N" (
     IF '%BROFMON_MOM_CLEAN_ONLY%' EQU 'false' (
        REM Append BROFMON MOM rollup log file to BROFMON MON log
        TYPE "%%N">> %BROFMON_MOM_LOG%
     )
     REM Clean the no longer needed BROFMON MOM rollup log file
     DEL "%%N"
    )
)

GOTO end

:ShowUsage
ECHO.
ECHO.MomBROFMON CentralReportingDir (BrofmonMomLogFile ^| /CLEAN)
ECHO.
ECHO.Description:
ECHO.    Appends individual BROFMON MOM rollup files into one BROFMON MOM log.
ECHO.
ECHO.Required Parameters:
ECHO.    CentralReportingDir            Specifies the location at which the
ECHO.                                   Central Reporting logs are stored.
ECHO.
ECHO.    BrofmonMomLogFile              Specifies the path and file name
ECHO.                                   where individual rollup files from
ECHO.                                   the CentralReportingDir will be
ECHO.                                   appended.
ECHO.
ECHO.    /CLEAN                         Causes the individual rollup files
ECHO.                                   to be deleted without appending
ECHO.                                   them to a BrofmonMomLogFile.
ECHO.
ECHO.                                   NOTE: Used instead of specifying 
ECHO.                                   a BrofmonMomLogFile.
ECHO.
ECHO.Examples:
ECHO.   MomBROFMON C:\BROFMON\REPORTS C:\BROFMON\MOM\MOM.log
ECHO.   MomBROFMON C:\BROFMON\REPORTS /CLEAN
ECHO.
ECHO.Additional help is available in the Branch Office Guide for Windows Server 2003.
ECHO.

:end
