Instantly share code, notes, and snippets.

Embed
What would you like to do?
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