Wait 20 seconds in a batch file

Hello!

I need a little help. I have a batch file that runs at startup on the server and sends a message to the two other PCs on the network to let them know that the server has rebooted (since it doesn't have a screen, it's the only solution we found...).

The problem is that when the client PCs receive the messages, the server’s network services aren’t launched yet. Based on that, if we put a 20-second pause before sending the messages in the batch, would that be enough? And if so, how would you put a 20-second pause in a batch file?

Thanks in advance.

Tabou Junior

9 answers

  • Votes
  • Date
  • Descending date
  1. Stop with your stupid pings:
    1) it's 0% reliable (yeah, the ping on the loopback is around 0 to 16ms, which is 1 clock tick under Windows, and if you don't have a network card, it doesn't work)
    2) it runs a program for no reason (and it uses COM for no reason)
    1. hi FFS ;)

      I don't agree with you!! because ping also works without a network card like mine ;)

      for 4 seconds: (n-1) ==> the n in this example is equal to 5
      ping -n 5 127.0.0.1
      or
      ping -n 5 localhost
    2. Contributor
      FFS 29 Jun 2010 at 3:39 PM
      Stop with your stupid ping:

      Propose an alternative, we're waiting .....
    3. Me ping works very well but me I type ping -n 1 1.1.1.1 -w 5000 >nul
    4. Re,

      PING /?

      Usage: ping [-t] [-a] [-n echoes] [-l size] [-f] [-i ttl] [-v TypeServ]
      [-r Hops] [-s Hops] [[-j HostsList] | [-k HostsList]]
      [-w Timeout] TargetName

      Options:
      -t Sends the ping request to the specified host until
      interrupted.
      Press Ctrl-Break to display statistics and continue,
      Ctrl-C to stop.
      -a Resolves hostnames from addresses.
      -n echoes Number of echo requests to send.
      -l size Sends the size of the buffer.
      -f Sets the Don't Fragment flag in the packet.
      -i ttl Time to live.
      -v TypeServ Type of service.
      -r Hops Records the route for the number of hops.
      -s Hops Timestamp for the number of hops.
      -j HostsList Loose source route along the host list.
      -k HostsList Strict source route along the host list.
      -w Timeout Timeout for each reply, in milliseconds.
    5. Contributor
      FFS :

      -w Waiting time for each response, in milliseconds.

      That's it for your point 1: it's reliable.
  2. Hi,
    another solution you can use is the SLEEP command..
    you can do a "SLEEP 20" and it will pause for 20 seconds
    I can send it to you if you want because I don't remember where I downloaded or found it!!
    1. Good night,
      yes choice will work if you write it with the following syntax:

      choice /c:ON /n /t:O,20

      where /n suppresses the display (Y/N) of the letters designated by /C:
      and /t: gives the default result O (Yes) in 20 seconds.

      The command and its switches are valid from DOS versions 6 to 8 (and ?? ...).

      Olivier Fournier
      1. slt

        the choice command does not exist in XP
    2. Otherwise, a little ping allows you to wait a bit.
      For example:

      ping -n 5 127.0.0.1 

      where '-n 5' is the duration of each ping. If you want to wait 20 seconds, I recommend
      ping -n 15 127.0.0.1 or... ping -n 20 127.0.0.1 
      1. Well, I know this topic is a bit old (a lot), but it can be useful for those looking for a solution.

        In Windows 7, there is the timeout command to add a pause.

        timeout /? for more info.
        1. Thank you, I should be able to manage with that...

          Taboo Junior
          1. Thank you all for your help... It works with choice! It's great :-))

            Taboo Junior