sbcsucks.sh
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
#!/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