Possible Duplicate:
How to sleep in a batch file?
I have a batch file that runs as a secheduled task in windows server 2003.
This batch file purely calls around 20 other batchfiles one after the other.
When this runs it causes quite a spike on the server and a reduction in performance.
I'd like the ability to add a WAIT or SLEEP type command between each of my batch file calls in order to spread the load out a bit.
Can anyone shed any light on the simplest way of doing this?
The correct way to sleep in a batch file is to use the
timeout
command, introduced in Windows 2000 Server and Windows XP.To wait 30 seconds:
The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch
/nobreak
, which effectively ignores anything the user may press, except an explicitCTRL-C
:Additionally, if you don't want the command to print its countdown on the screen, you can redirect its output to
NUL
:There's a W2K3 resource kit utility called sleep.exe that you can use by calling it in the batch file and telling it how long to "sleep" before moving on to the next command.
Example:
net use X: \server\share /Delete
sleep 300
net use X: \server\share
The best way is to use 'ping', but you can find more ways here: http://drbatcher.blogspot.com/2009/10/pauses-and-delays-in-batch-scripts.html
The code you are looking for, looks like this:
ping -n 11 127.0.0.1 > NUL
The value after "-n" indicates the seconds to wait.
If you want to wait 10secs just add one more ping,
like shown in the example.
Best regards.
P.S.: If you use the powershell, there may be other ways to do this.