Created
February 23, 2018 19:14
-
-
Save dtiemann83/d8d91cc29d2fcb5ffb0736d4467dbc00 to your computer and use it in GitHub Desktop.
Script to display all of the hostnames and addresses in your SSH config
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
#!/bin/bash | |
# Script to display all of the hostnames and addresses in your SSH config! | |
COLOR=$(tput setaf 2) | |
NCOL=$(tput sgr0) | |
hosts=``; | |
cat ~/.ssh/config | grep 'Host' | while read -r line ; do | |
nline=`echo $line | sed -e 's/[[:space:]]*Hostname[[:space:]]*//g' -e 's/[[:space:]]*Host[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e 's/[[:space:]]/*/g'` | |
if ! [[ $line =~ ^Hostname ]]; then | |
curhost=$nline; | |
fi | |
if [[ $line =~ ^Hostname ]]; then | |
printf "%20s : " "$curhost"; | |
printf "%s\n" "$COLOR$nline$NCOL"; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment