Solved

Need a batch script with Timer

Posted on 2014-02-28
5
570 Views
Last Modified: 2014-05-19
I have a XCOPY script in which I would like to know how long it took to execute. This timer information can just be sent to a LOG file, for ease and historical information.

Can you build a timer around my script?

xcopy \\CGIGEHRSQLCLU02\h$\DBBackup C:\BE.UNC.BACKUPS\SQL.BAK.TEMP\ /S /C /Q /Y /Z /J
xcopy \\Cgigehrsqlclu02\h$\DBBackup\IGEHR_PROD\*.BAK C:\BE.UNC.BACKUPS\SQL.BAK.TEMP\EIGRP_PROD /S /C /Q /Y /Z /J
xcopy \\Cgigehrsqlclu02\h$\DBBackup\IGEHR_PROD_Imaging\*.bak C:\BE.UNC.BACKUPS\SQL.BAK.TEMP\IGEHR_PROD_Imaging  /S /C /Q /Y /Z /J

Open in new window

0
Comment
Question by:Glenn M
5 Comments
 
LVL 26

Accepted Solution

by:
pony10us earned 500 total points
ID: 39896080
It could be something as simple as this?

@echo off
echo Start Step 1 %time% >> <drive>:\<folder>\<filename>
xcopy \\CGIGEHRSQLCLU02\h$\DBBackup C:\BE.UNC.BACKUPS\SQL.BAK.TEMP\ /S /C /Q /Y /Z /J
echo Start Step 2 %time% >> <drive>:\<folder>\<filename>
xcopy \\Cgigehrsqlclu02\h$\DBBackup\IGEHR_PROD\*.BAK C:\BE.UNC.BACKUPS\SQL.BAK.TEMP\EIGRP_PROD /S /C /Q /Y /Z /J
echo Start Step 3 %time% >> <drive>:\<folder>\<filename>
xcopy \\Cgigehrsqlclu02\h$\DBBackup\IGEHR_PROD_Imaging\*.bak C:\BE.UNC.BACKUPS\SQL.BAK.TEMP\IGEHR_PROD_Imaging  /S /C /Q /Y /Z /J
echo Job complete %time% >> <drive>:\<folder>\<filename>

Open in new window

0
 
LVL 16

Expert Comment

by:choward16980
ID: 39896107
I use this a lot:

http://stackoverflow.com/questions/739606/how-long-a-batch-file-takes-to-execute


@echo off
setlocal

rem Remeber start time. Note that we don't look at the date, so this
rem calculation won't work right if the program run spans local midnight.
set t0=%time: =0%

rem do something here.... but probably with more care about quoting.
rem specifically, odd things will happen if any arguments contain 
rem precent signs or carets and there may be no way to prevent it.
%*

rem Capture the end time before doing anything else
set t=%time: =0%

rem make t0 into a scaler in 100ths of a second, being careful not 
rem to let SET/A misinterpret 08 and 09 as octal
set /a h=1%t0:~0,2%-100
set /a m=1%t0:~3,2%-100
set /a s=1%t0:~6,2%-100
set /a c=1%t0:~9,2%-100
set /a starttime = %h% * 360000 + %m% * 6000 + 100 * %s% + %c%

rem make t into a scaler in 100ths of a second
set /a h=1%t:~0,2%-100
set /a m=1%t:~3,2%-100
set /a s=1%t:~6,2%-100
set /a c=1%t:~9,2%-100
set /a endtime = %h% * 360000 + %m% * 6000 + 100 * %s% + %c%

rem runtime in 100ths is now just end - start
set /a runtime = %endtime% - %starttime%
set runtime = %s%.%c%

echo Started at %t0%
echo Ran for %runtime%0 ms

Open in new window



It's pretty extensive and friendly with the notation
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39896191
I've got a bit of a shorter one I have written here if you want too:

http://scripts.dragon-it.co.uk/links/batch-find-time-taken

Steve

REM =======================================
REM Set of subroutines to make time differences easier in batch files using VBScript to do the maths.
REM Steve Knight, Aug 2012
REM http://scripts.dragon-it.co.uk/
REM =======================================
REM Call :START to "Start the clock"
REM Call :END to "Stop the clock"
REM Call :ShowDiff x to show the difference where x is s, n, h for secs, mins, hours
REM Once STARTed you can do multiple ENDs or do another START to reset
REM =======================================

REM =======================================
REM Examples
REM =======================================
call :START
echo Waiting
ping 127.0.0.1 -n 4 > NUL
call :END
call :ShowDiff s

call :START
echo Waiting
ping 127.0.0.1 -n 45 > NUL
CALL :END
call :ShowDiff s

echo Continuing
ping 127.0.0.1 -n 90 > NUL
CALL :END
call :ShowDiff n

EXIT/B
REM =======================================
REM Subroutines below here
REM =======================================
:START
set start=%date% %time:~0,8%
echo START at %start%
exit /b

:END
set end=%date% %time:~0,8%
echo END at %end%
exit /b

:ShowDiff
REM Call with s,n,h for seconds, mins, hours. defaults to secs
(set type=%~1)& if "%~1"=="" set type=s

echo Wscript.Echo DateDiff("%type%", #%start%#,#%end%# ) > "%temp%\timediff.vbs"
for /f %%s in ('cscript //nologo "%temp%\timediff.vbs"') do set TimeDiff=%%s
del "%temp%\timediff.vbs"
if %Type%==n set type=m
echo TIME TAKEN: %TimeDiff% %Type%
exit /b

Open in new window

0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39896459
I actually prefer to use a small EXE utility for this job, take a look at this freebie that does a nice job:

http://www.gammadyne.com/cmdline.htm#timer

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40075773
Sometimes wonder why you bother!
0

Featured Post

How our DevOps Team Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

825 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