One way to do ping is to loop, for example
while ! ping -c 1 host; do sleep 1; done
(You can redirect the output to /dev/null if you want it to be quiet.)
On some systems, such as Mac OS X, ping , the -a -o options may also be available (according to another answer), which will cause it to continue to ping until it receives a response. However, ping for many (most?) Linux systems does not have the -o option, and the equivalent type -c 1 -w 0 will still exit if the network returns an error.
Edit: if the host does not respond to ping or you need to check the availability of the service on a specific port, you can use netcat in zero input / output mode:
while ! nc -w 5 -z host port; do sleep 1; done
-w 5 sets a 5 second timeout for each individual attempt. Note that with netcat, you can even list several ports (or port ranges) for scanning when some of them become available.
Edit 2: The loops shown above continue to try until the host (or port) is reached. Add your alert command after them, for example. beep or popup.
source share