Created
May 12, 2016 00:21
-
-
Save nxtonic/09820c4ebe2b6a25e9ec55ae44ba3460 to your computer and use it in GitHub Desktop.
a quick bash script with a notification when the internet connection is up / restored
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
#!/bin/bash | |
SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; | |
ESC=$(printf "\e"); Ys="$ESC[33m"; Ye="$ESC[0m"; Rs="$ESC[31m"; Re="$ESC[0m"; | |
P=$(echo "$ESC[35m[${BASH_SOURCE[0]}]$ESC[0m"); | |
before_exit () { | |
if ping -c 1 google.com &> /dev/null | |
then { | |
echo "$P Yay, there is internet!"; | |
exit 0; | |
} else { | |
echo "$P can't connect, trying again..."; | |
sleep 1; | |
before_exit; | |
} | |
fi | |
} | |
clean_exit () { | |
sleep 0.5; | |
echo "$P exiting..."; | |
if [[ `uname -s` == "Darwin" ]]; | |
then | |
osascript -e 'display notification "Have a great day!" with title "Internet is up!" sound name "Hero"' | |
fi | |
sleep 0.5; | |
} | |
trap clean_exit 0; | |
before_exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment