Pausing in shell scripts

| | Comments (1)
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 ping command to create a delay.

Within a DOS batch file you can execute the following:
ping -n 1 -w 1000 >NUL
By modifying the -w 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 >/dev/null
You don't get millisecond precision with the UNIX version of ping. Modify the -i 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 ping to send 2 packets to your local machine and to wait for -i 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.

Update: Alright, I've already been informed twice of the existence of the unix command sleep. Just between you and me though, the cool people use ping.


i cannot find any cool factor in abusing the ping command...

Leave a comment

About this Entry

This page contains a single entry by Dylan published on August 22, 2004 10:47 PM.

satisfaction was the previous entry in this blog.

Virtually Topless is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.