Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a batch script for backup recently. Somewhere in the middle of script I'll have to wait for some time to be reached and then resume the next line of the script. I've scheduled the script at 4:00PM and after the wait command the next line should start at exactly 5:30PM. I thought of using SLEEP command but it's not sure that the commands used before the wait command will end up at certain time(due to inconsistent file sizes) but it's sure that they will be done by 5:00 or 5:10 and next it should execute wait command which waits for certain system clock. I'm checking if there is any command that waits or sleeps until the time specified reaches the system time and resumes there after. Anybody came across this situation and how was that resolved?

share|improve this question
up vote 2 down vote accepted

Probably not the best way to do this, but here goes:

if %TIME% LSS 17:30:00.00 goto loop
echo Continuing at %TIME%
share|improve this answer
It may work and I should try that and ofcourse as you said it's not recommended making server busy for unnecessary work. – user53864 Jan 29 '11 at 12:52
It works but it may be continuously executing the loop statement til 17:30. Isn't it possible like set n=presenttime-17:30 and then sleep n something like that which you could do? – user53864 Jan 31 '11 at 11:49
@user: Most of that type of command take a number of seconds as a parameter. You can do a calculation to get that value (it would be 17:30-presenttime rather than the way you had it, but the syntax would be more complex). Take a look at the timeout command and check the Resource Kits for a sleep command. – Dennis Williamson Jan 31 '11 at 14:53

You're using two tags, WinXP and Server-2008-R2, so I'm not sure which environment you're running in.

Both environments have a command called schtasks that allows setting up scheduled tasks from the command-line, though the capabilities of this tool varies with the platform. It will allow you to set up a one-time task that will call the remainder of your script. It'll have to be in a separate file, but it'll get executed a single time at 5:30pm.

XP Syntax:

Server-2008 Syntax:

share|improve this answer
will it run at 5:30 if I append schtaskts schedule command in place of wait?. – user53864 Jan 29 '11 at 12:47
will it wait till 5:30 and start schedule command? – user53864 Jan 29 '11 at 15:29

I don't know about any command to wait for a specific time but you might find some Googling for it. We solve similar issues by chopping the batch files into separate parts and scheduling them individually.

share|improve this answer
Actually I don't want to run separately as I have many scheduled tasks and it's a bit confusing when I want to search for a particular task. So I thought of making it a single batch script. – user53864 Jan 29 '11 at 12:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.