Skip to content

Instantly share code, notes, and snippets.

@dtiemann83
Created February 23, 2018 19:14
Show Gist options
  • Save dtiemann83/d8d91cc29d2fcb5ffb0736d4467dbc00 to your computer and use it in GitHub Desktop.
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
#!/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