Created
May 4, 2018 15:20
-
-
Save ttscoff/6e041346fd10834c0ae48599b45e9276 to your computer and use it in GitHub Desktop.
Bash functions for notifying when your internet connection comes back up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash functions for notifying when your internet connection comes back up | |
# A truly atrocious way to get your attention | |
nag() { | |
while true; do | |
for phrase in "$@"; do | |
afplay /System/Library/Sounds/Ping.aiff | |
say "$phrase" | |
sleep 3 | |
done | |
done | |
} | |
# Use the [Pushover](https://pushover.net/) API to send a notice to your phone/watch | |
pushnotify() { | |
local token=xxxxxxxxxxxxxxxxxxx | |
local key=xxxxxxxxxxxxxxxxxxx | |
local formdata="token=${token}&user=${key}&title=$(urlenc $1)&message=$(urlenc $2)&priority=1&sound=spacealarm" | |
curl -X POST -d $formdata 'https://api.pushover.net/1/messages.json' | |
} | |
# Poll a DNS resolver to see when you can reach it, then notify | |
imdown() { | |
until ping -W1 -c1 8.8.8.8; do | |
sleep 5; | |
done | |
pushnotify "Internet connection restored" "Your internet connection is operational again" | |
nag \ | |
"internet connection is back up\!" \ | |
"Skynet is thinking" "your tribulation is over\!" \ | |
"Praise what gods may be. internet\!" \ | |
"O M G we're online" \ | |
"In the words of Dr. Frankenstein, it's alive\!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment