Skip to content

Instantly share code, notes, and snippets.

@tdlm
Last active May 24, 2019 17:28
Show Gist options
  • Save tdlm/866e777fd6310d43aad05720347b9ee6 to your computer and use it in GitHub Desktop.
Save tdlm/866e777fd6310d43aad05720347b9ee6 to your computer and use it in GitHub Desktop.
Connectivity checker bash script
#!/usr/bin/env bash
# Alerts
verbal_alert() {
say "Internet Connection is currently down"
}
display_alert() {
# See https://code-maven.com/display-notification-from-the-mac-command-line
osascript -e 'display notification "Internet Connection is currently down" with title "Internet Connectivity" subtitle "Google Unreachable"' 2&>/dev/null
}
# Connectivity check
# See https://unix.stackexchange.com/a/190610/229935
if ! nc -zw1 google.com 443 2&>/dev/null; then
display_alert
verbal_alert
fi

Connectivity Checker

Intermittently check to see if your Internet connection is up and running.

Installation

  1. Create and paste the code for connectivity_checker into a corresponding file in /usr/local/bin and make sure to chmod +x /usr/local/bin/connectivity_checker
  2. From your command line, type crontab -e
  3. Within the crontab editor, make a new line
  4. Enter */5 * * * * /usr/local/bin/connectivity_checker to check every 5 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment