Created
November 22, 2017 16:11
-
-
Save hazcod/b302790b2ed8d50e427edac596e89246 to your computer and use it in GitHub Desktop.
Fix openconnect routes after disconnect
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 | |
PATTERN="State:/Network/Service/utun[0-9]+/DNS" | |
REMOVE_RECORD_CMD="" | |
REMOVE_RECORD_MSG="RECORDS TO REMOVE:\n" | |
echo "Killing openconnect.." | |
sudo pkill openconnect | |
RECORDS=`scutil <<EOF | |
list $PATTERN | |
quit | |
EOF` | |
echo "Retrieving records.." | |
for RECORD in `echo $RECORDS`; do | |
if [[ "$RECORD" =~ "State" ]]; then | |
REMOVE_RECORD_CMD="${REMOVE_RECORD_CMD}remove $RECORD \n" | |
REMOVE_RECORD_MSG="${REMOVE_RECORD_MSG}$RECORD \n" | |
fi | |
done | |
echo "Cleaning up openconnect routes.." | |
if [ "x$REMOVE_RECORD_CMD" != "x" ]; then | |
printf "$REMOVE_RECORD_MSG" | |
sudo scutil <<EOF | |
`printf "$REMOVE_RECORD_CMD"` | |
quit | |
EOF | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment