Solved

Insert host name into master log file relating to data being copied

Posted on 2014-03-13
3
333 Views
Last Modified: 2014-03-13
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.
@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

Open in new window


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.
0
Comment
Question by:samiam41
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39927087
Try it with this:
@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

Open in new window

0
 
LVL 9

Author Comment

by:samiam41
ID: 39927114
THAT IS SOOO COOL!!

Hahahaha!!  That's perfect!  Thank you so much for your help!

~Aaron
0
 
LVL 9

Author Comment

by:samiam41
ID: 39927139
Another idea just popped up.  When (if) you get a chance.

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_28387970.html
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question