Sometimes in the middle of a shell script you may need to have a command pause for a few seconds, minutes or hours. Although there are some simple programs you can download to help you with this, few realize that you can also just use the
command to create a delay.
Within a DOS batch file you can execute the following:
ping -n 1 -w 1000 18.104.22.168 >NUL
By modifying the
parameter value, you can specify the amount of time to wait for a reply in milliseconds. The above will wait for 1 second. You do need to make sure the address you are trying to ping is unreachable, otherwise the command will finish quicker.
The UNIX equivalent is the following:
ping -c 2 -n -i 1 127.0.0.1 >/dev/null
You don't get millisecond precision with the UNIX version of ping. Modify the
parameter to specify the delay in seconds. This method of creating a delay doesn't rely on a non-reachable address, instead you are setting
to send 2 packets to your local machine and to wait for
seconds in between.
Nifty, eh? I used these methods to upload a webcam image to a server once a minute from both a Windows and UNIX machine.
Alright, I've already been informed twice of the existence of the unix command
. Just between you and me though, the cool people use