Skip to content

Instantly share code, notes, and snippets.

@shichao-an
Last active February 25, 2016 07:53
Show Gist options
  • Save shichao-an/dee61d0ac7d9134e3e5c to your computer and use it in GitHub Desktop.
Save shichao-an/dee61d0ac7d9134e3e5c to your computer and use it in GitHub Desktop.
sbcsucks.sh
#!/usr/bin/env bash
# Check if SBC is stable and send a notification
OUTSIDE_HOST="${1:-8.8.8.8}"
PING_COUNT=15
PING_TIMEOUT=15
PING_INTERVAL=0.5
ASC_MBP="10.0.1.10"
STATUS="unknown"
while true; do
PERCENT_LOSS=$(
ping -W "$PING_TIMEOUT" -c "$PING_COUNT" -i "$PING_INTERVAL" \
"$OUTSIDE_HOST" \
| grep -o '[0-9]*% packet loss' | awk '{ print $1 }'
)
echo -en "$PERCENT_LOSS packet loss.\r"
if [ "$PERCENT_LOSS" = "0%" ]; then
if [ "$STATUS" = 'stable' ]; then
continue
fi
STATUS=stable
ssh -i ~/.ssh/asc-mbp shichao@"$ASC_MBP" "osascript -e 'display \
notification \"Network is stable now.\" with title \"Reminder\"'"
else
if [ "$STATUS" = 'unstable' ]; then
continue
fi
STATUS=unstable
ssh -i ~/.ssh/asc-mbp shichao@"$ASC_MBP" "osascript -e 'display \
notification \"Network has $PERCENT_LOSS packet loss.\" with title \"Reminder\"'"
fi
sleep 2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment