ping a host until it responds, then play a sound, then exit

beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
After this, just type: beepwhenup You need to install "beep" before this would make the beep sound. Save it in your .profile if you want to use it later WARNING: this command won't exit until it is successful. You won't be able to CONTROL+C out of it.

2009-09-24 18:11:10

2 Alternatives + Submit Alt

What Others Think

Rather than installing the 'beep' program, on some consoles you can run this for a beep: echo -en "\x07"
devrick0 · 635 weeks and 4 days ago
You can achieve this with just ping. ping -a -c 1 -a is emit audible bell -c is exit after receiving count replies in this case one
haplo · 635 weeks and 4 days ago
@haplo: nope. A certain number of pings may be more or less than is needful before you hear a sound. The code presented will only beep when the host finally responds-- not until an arbitrary ping count has been reached. However you are correct about the "-a" flag to the extent that it "works". It simply does not emit any sound when I use it on my ubuntu workstation.
linuxrawkstar · 635 weeks and 3 days ago
Created 2 scripts for MacOS : sayping and saytcping The second one uses tcping, (C) 2003 Just want to share them but cannot attach files here ;(
theunf · 289 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: