samiam41
asked on
Save log file as date {batch script output file}
Hi Experts! I have another question since I can't seem to get it right and don't have the time to play with it.
I have a script that copies text from multiple text files and dumps it to a single "master" text file. I need the single/master text file to have the name that matches the date that is being searched.
Example; if I am looking for the data for 03/13/2014, I need the master text file to be named Master_Log_File_03-13-2014 .log. The very first thing the script does is asks what date you are searching for:
How can I set the text file to be named what the search date is? Thanks for your help.
I have a script that copies text from multiple text files and dumps it to a single "master" text file. I need the single/master text file to have the name that matches the date that is being searched.
Example; if I am looking for the data for 03/13/2014, I need the master text file to be named Master_Log_File_03-13-2014
How can I set the text file to be named what the search date is? Thanks for your help.
@echo off
setlocal enabledelayedexpansion
set CentralLog=Z:\Logs\TSM_Backups\Combined_TSMLogs.log
if "%~1"=="" (
set FindDate=
set /p FindDate=Enter date to search:
) else (
set FindDate=%~1
)
if "%FindDate%"=="" goto :eof
set CopyBegin=SCHEDULEREC STATUS BEGIN
set CopyEnd=SCHEDULEREC STATUS END
for /f "tokens=1 delims=[]" %%a in ('type "%~f0" ^| find /i /n "[DATA]"') do set DataStart=%%a
for /f "skip=%DataStart% delims=" %%a in ('type "%~f0"') do (
set LogFile=%%a
if "!LogFile:~0,2!"=="\\" (
for /f "delims=\" %%s in ("!LogFile!") do set Server=%%s
) else (
set Server=%ComputerName%
)
echo Processing '!LogFile!' on !Server! ...
set /a CopyFound = 0
set /a Copy = 0
for /f "delims=" %%b in ('type "!LogFile!" ^| findstr.exe "^%FindDate%"') do (
set Line=%%b
if !Copy!==0 (
if not "!Line!"=="!Line:%CopyBegin%=!" (
set /a CopyFound = 1
set /a Copy = 1
>>"%CentralLog%" echo ========== !Server! Start ============================================================
>>"%CentralLog%" echo !Line!
)
) else (
>>"%CentralLog%" echo !Line!
if not "!Line!"=="!Line:%CopyEnd%=!" (
set /a Copy = 0
>>"%CentralLog%" echo ========== !Server! End ============================================================
)
)
)
if !CopyFound!==0 (
echo No match found in '!LogFile!'.
)
)
goto :eof
[DATA]
\\w2k3ps01\d$\Program Files\Tivoli\TSM\baclient\dsmsched.log
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks oBdA!
~Aaron