Last active
February 14, 2019 11:46
-
-
Save tckb/9489519 to your computer and use it in GitHub Desktop.
Small bash script for notifying the internet connection. Raises a notification when connection is lost.
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 | |
# Author: tckb<[email protected]> | |
# Ping notification using terminal- notifier; for OsX | |
# Usuage: ./notify_ping.sh <check_freq_seconds> & | |
rm $HOME/.np_click 2>/dev/null | |
if [ -z ${1} ] | |
then | |
freq=5 #check every 5 seconds | |
else | |
freq=$1 | |
fi | |
echo >Checking freq $freq seconds | |
#check if notifier is installed | |
echo ">Checking for terminal-notifier ..." | |
hash terminal-notifier >& /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo ">Installing notifier..." | |
sudo gem install terminal-notifier | |
fi | |
echo ">Testing internet connection...." | |
while [ 1 ] | |
do | |
if [[ -e $HOME/.np_click ]]; then | |
echo ">User click detected!" | |
rm $HOME/.np_click | |
if [ $freq -gt 10 ]; then | |
echo ">Probably too many notifcations -- user annoyed! terminating :P" | |
terminal-notifier -message "Too many notifications, terminating ping notifier!. Re-run to start notifier" -title "Ping notifier" 2>/dev/null | |
exit 0 | |
else | |
echo ">Increasing checking freq..." | |
freq=`expr $freq + 5` | |
echo ">Update frequency: $freq" | |
fi | |
fi | |
ping -c 5 google.com >& /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo ">Your connection is dead!! muwahahahah -- okay, notifying" | |
terminal-notifier -message "Internet connection lost @ `date`" -title "Ping notifier" -execute "touch $HOME/.np_click" 2>/dev/null | |
else | |
echo ">It's alive!" | |
fi | |
sleep $freq | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment