Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need a batch script with Timer

Posted on 2014-02-28
5
Medium Priority
?
586 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 26

Accepted Solution

by:
pony10us earned 2000 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 58

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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