Solved

Need a batch script with Timer

Posted on 2014-02-28
5
574 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 54

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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