Skip to content

Instantly share code, notes, and snippets.

@adrianlshaw
Last active January 28, 2018 16:40
Show Gist options
  • Save adrianlshaw/42a65447bacaa68734df0283f8dff18d to your computer and use it in GitHub Desktop.
Save adrianlshaw/42a65447bacaa68734df0283f8dff18d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
FILE=$(realpath ~/.ssh/config)
THEPORT=""
THEHOST=""
THEADDR=""
while read -r name
do
echo "DBG: $name"
KEY=$(echo "$name" | cut -d ' ' -f1)
VALUE=$(echo "$name" | cut -d ' ' -f2)
if [ "$KEY" == "Host" ]; then
THEHOST=""
THEPORT=""
THEADDR=""
THEHOST="$VALUE"
fi
if [ "$KEY" == "HostName" ]; then
THEADDR="$VALUE"
fi
if [ "$KEY" == "Port" ]; then
THEPORT="$VALUE"
fi
if [[ -n "$THEADDR" && -n "$THEPORT" ]]; then
echo "Checking $THEHOST"
nc "$THEADDR" "$THEPORT" -w 1
echo "$? returned by nc $THEADDR $THEPORT -w 1"
fi
done < "$FILE"
echo "Exited"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment