Solved

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

Posted on 2014-03-13
3
324 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 83

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now