Wait 20 seconds in a batch file

Taboujr Posted messages 507 Status Member -  
 bustvhk -
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

  1. FFS
     
    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)
    6
    1. karirovax Posted messages 3584 Status Member 215
       
      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
      0
    2. titonisme
       
      Me ping works very well but me I type ping -n 1 1.1.1.1 -w 5000 >nul
      0
    3. karirovax Posted messages 3584 Status Member 215
       
      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.
      0
    4. HostOfSeraphim Posted messages 7340 Status Contributor 1 609
       
      FFS :

      -w Waiting time for each response, in milliseconds.

      That's it for your point 1: it's reliable.
      0
    5. bustvhk
       
      Hello,
      Yes ping = poop
      Use the command TIMEOUT /t 30 /NOBREAK
      here in the example, a pause of 30 seconds
      0
  2. gigilafleur Posted messages 96 Registration date   Status Member 8
     
    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!!
    4
  3. ofournier.cbd Posted messages 5862 Registration date   Status Member Last intervention   84
     
    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
    3
    1. karirovax Posted messages 3584 Status Member 215
       
      slt

      the choice command does not exist in XP
      0
  4. MacUSer
     
    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 
    3
  5. Poulet
     
    It's not really the most appropriate command, but it does allow for a pause... The CHOICE command

    http://1100f.free.fr/Batchs/la_commande_choice.htm

    If the user does not respond, a default signal is sent to execute the script. I hope it will be okay.

    Patapi Biribibi Rabada dada
    Dada dada !!
    2
  6. Northfacts
     
    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.
    2
  7. Taboujr Posted messages 507 Status Member 117
     
    Thank you, I should be able to manage with that...

    Taboo Junior
    0
  8. Taboujr Posted messages 507 Status Member 117
     
    Thank you all for your help... It works with choice! It's great :-))

    Taboo Junior
    0