Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash functions for notifying when your internet connection comes back up
# 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