samiam41
asked on
Insert host name into master log file relating to data being copied
Hi Experts. In what will likely be the last upgrade to this script for a little while, I would like to insert the name of the server that the data being copied from relates to, using this script.
When the data is copied from multiple servers, there is no reference in the master log file as to which server the data is coming from. I need to add this to make the log file useful.
Thank you.
@echo off
setlocal enabledelayedexpansion
set CentralLog=D:\Temp\test_Central.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 (
echo Processing '%%a' ...
set /a CopyFound = 0
set /a Copy = 0
for /f "delims=" %%b in ('type "%%a" ^| 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 !Line!
)
) else (
>>"%CentralLog%" echo !Line!
if not "!Line!"=="!Line:%CopyEnd%=!" (
set /a Copy = 0
)
)
)
if !CopyFound!==0 (
echo No match found in '%%a'.
)
)
goto :eof
[DATA]
\\w2k3ps01\d$\Program Files\Tivoli\TSM\baclient\dsmsched.log
When the data is copied from multiple servers, there is no reference in the master log file as to which server the data is coming from. I need to add this to make the log file useful.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Another idea just popped up. When (if) you get a chance.
https://www.experts-exchange.com/questions/28387970/Save-log-file-as-date-batch-script-output-file.html
https://www.experts-exchange.com/questions/28387970/Save-log-file-as-date-batch-script-output-file.html
ASKER
Hahahaha!! That's perfect! Thank you so much for your help!
~Aaron