Skip to content

Instantly share code, notes, and snippets.

@pierdom
Last active September 7, 2017 07:56
Show Gist options
  • Save pierdom/561ca780c0a415bbd7a54d2ffec4781c to your computer and use it in GitHub Desktop.
Save pierdom/561ca780c0a415bbd7a54d2ffec4781c to your computer and use it in GitHub Desktop.
[until bash command] An example on how to use the until command on bash to check when connectivity is back #linux #macosx #syadmin

Example: ping google.com until it becomes reachable (for testing when internet connection is back), then notify with an audio message

until ping -W1 -c1 google.com; do sleep 5; done && say connected

It's also possible to use different notification means (e.g., notify-send on Ubuntu, growl on Mac, pushover, etc.).

Notes on ping:

ping -W1 -c1 google.com

means ping just once (-c1) and wait for reply for 1 second (-W1). It returns 0 if host is reachable, error otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment