Skip to content

Instantly share code, notes, and snippets.

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 martindevans/2a371e5199e0f0dbb65a3fde2b3b0875 to your computer and use it in GitHub Desktop.
Save martindevans/2a371e5199e0f0dbb65a3fde2b3b0875 to your computer and use it in GitHub Desktop.
#!/bin/bash
IP='google.co.uk'
STATUS_FILE="/home/martin/SpeakingAssistant/state/netstate"
LOG_FILE="/home/martin/SpeakingAssistant/state/netstate.log"
if [ -r $STATUS_FILE ]; then
STATUS=`cat $STATUS_FILE`
else
STATUS="unknown"
fi
HOUR="$(date +"%H")"
SPEAK=$(( $HOUR < 3 || $HOUR > 10 ));
fping -c5 -t1000 $IP 2>/dev/null 1>/dev/null
if [ "$?" = 0 ]
then
#network is up
echo "connection is up"
echo "up" > $STATUS_FILE
if [ $STATUS != "up" ];
then
if [ $SPEAK ]
then
echo "Speaking..."
mplayer /home/martin/SpeakingAssistant/VoiceLines/NetworkUp.wav
fi
echo "$(date) UP" >> $LOG_FILE
fi
else
#network is down
echo "connection is down"
echo "down" > $STATUS_FILE
if [ $STATUS != "down" ];
then
if [ $SPEAK ]
then
echo "Speaking..."
mplayer /home/martin/SpeakingAssistant/VoiceLines/NetworkDown.wav
fi
echo "$(date) DOWN" >> $LOG_FILE
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment