Demartek Lab Testing

Demartek performs hands-on lab validation tests for computer hardware and software products targeted at the small and medium business (SMB) marketplace and the large enterprise.

Do you need to test a particular application workload but don’t have the lab resources to test it?

Do you need external validation of a hardware or software solution?

Contact us to discuss how we can provide testing, analysis and white papers.

Dennis Martin often shares test results from the Demartek lab when he speaks at conferences, user group meetings, etc. View his speaking schedule at the Events & Speaking page.

Related Demartek Content


Sign-up for the Demartek Newsletter!

Demartek Lab Tips — Time-related Scripting Functions

We do a fair amount of scripting in our validation and performance testing, and we often require time-related functions for our batch files on our Windows machines. These time-related functions can be divided into three categories:

Windows batch files are unformatted text files that contain one or more commands and have a .bat or .cmd file name extension. We have found that it is best to save these files using the default ANSI/ASCII encoding, rather than UTF-8 or other encoding schemes.


Display the Date and/or Time

The get the date and/or time in a batch file, simply use the native date or time commands with the “/t” option. The “/t” option simply displays the date or time without changing it. These two commands work well if you need to capture a simple date or time. These two commands have been available in Windows for many years.

A handy way to get a little more precision with the date or time commands is to pipe them with the echo command like this:

echo | time | find "is:"
Which results in:
The current time is: 14:16:11.37

However, we like to better document our scripts to provide additional information with a time stamp. For this, I’ve been using the now.exe utility that has been available for several years, originally appearing in the Windows 2000 Resource Kit from Microsoft and is also available in the Windows Server 2003 Resource Kit (see links below). The now.exe utility not only provides the date and time together on one output line, but also allows for optional text to be displayed with it. For example, we often use something like the following command in our scripts:

now step 1 of 4
The output from this command is
Mon Jul 25 09:07:01 2011 -- step 1 of 4
This output provides not only the date and time but some documentation regarding the progress in the batch file. We like to pipe this output into a job log text file.


Wait

It is often necessary to wait for a period of time to allow disk caches to completely flush or other threads to finish before proceeding with subsequent steps in a batch file. Recent versions Windows have added the timeout command that can be used for this purpose. The simple form of the timeout command uses the “/t” option to indicate a number of seconds to wait. The command simply waits, has no output, and in its most simple form, is used like this:

timeout /t 10
This tells the script to wait 10 seconds before proceeding. There are a couple of other options available to ignore key presses or wait indefinitely.

If you are using Windows XP or older, there is no native timeout command. For many years, I have been using sleep.exe, which was originally provided in the Windows 2000 Resource Kit and is also available in the Windows Server 2003 Resource Kit (see links below). Sleep.exe is a very simple utility that waits the desired number of seconds, and is used like this:

sleep 10
This tells the script to wait 10 seconds before proceeding.

If you are not running unattended and want something a little more interactive, you might want to include the choice command in a loop that can wait for some time while prompting for an answer. Choice.exe is available on recent versions of Windows. The following code snippet shows how this works:

:loop
Echo Do something here
choice /t 10 /m "Waiting for 10 seconds. Continue? " /c ny /d y
if errorlevel 2 goto loop


Time Synchronization

Synchronizing the clocks on multiple machines is essential when running tests, especially when using virtual machines. The net time command has been available in Windows for quite a while and is used to synchronize the clock on the current machine to the clock on another machine. The net time command must be used on an account with full Administrator privileges, or using the “run as Administrator” option. In this example, the machine with the correct time is called PrimaryMachine. The syntax for the net time command in a script is:

net time \\PrimaryMachine /set /y
The /y option is used to automatically answer the “do you really want to do this” question.


Links


More information

To be notified when we post new deployment guides, evaluation reports and commentaries, sign-up for our free monthly newsletter, Demartek Lab Notes. We do not give out, rent or sell our email list.