Skip to content

Instantly share code, notes, and snippets.

@vaughany
Created October 28, 2020 12:14
Show Gist options
  • Save vaughany/f55252643abc1824ba5cfe6377894efd to your computer and use it in GitHub Desktop.
Save vaughany/f55252643abc1824ba5cfe6377894efd to your computer and use it in GitHub Desktop.
Tests the VPN's status by ssh-ing to an IP address only accessible when the VPN is up and running a basic command. Runs less frequently on success, very frequently on failure.
#!/bin/bash
shellcheck "$0" || exit 1
IP=1.2.3.4
OUT=test-ssh.log
DELAY_MIN=2
DELAY_MAX=128
DELAY=$DELAY_MIN
truncate -s 0 $OUT
clear
while true; do
ssh $IP -o ConnectTimeout=1 -o LogLevel=error date > >(tee -a $OUT) 2> >(tee -a $OUT >&2)
if test $? == 0; then
DELAY=$(( DELAY * 2 ))
if (( DELAY > DELAY_MAX )); then
DELAY=$DELAY_MAX
fi
echo -n "✔️ "
else
DELAY=$DELAY_MIN
echo -n "❌ "
fi
echo "Sleeping $DELAY seconds... "
sleep $DELAY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment