Skip to content

Instantly share code, notes, and snippets.

@mariuswilms
Created June 20, 2014 19:28
Show Gist options
  • Save mariuswilms/56fd63b6a251254ba311 to your computer and use it in GitHub Desktop.
Save mariuswilms/56fd63b6a251254ba311 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Continuously checks online/offline status and notifies
# you when the status changes. Works only where the "say"
# command is available.
#
# Dedicated to the public domain.
#
last=
while true; do
ping -o -t 2 www.google.de &>/dev/null
cur=$?
if [[ $cur != 0 ]]; then
echo -n "0"
else
echo -n "1"
fi
if [[ $cur != $last ]]; then
if [[ $cur != 0 ]]; then
say "offline"
else
say "online"
fi
last=$cur
fi
sleep 2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment