Skip to content

Instantly share code, notes, and snippets.

@nxtonic
Created May 12, 2016 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nxtonic/09820c4ebe2b6a25e9ec55ae44ba3460 to your computer and use it in GitHub Desktop.
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
#!/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