Auto aliasing of ssh hosts

A

if [ -d ~/.ssh ]; then

# Touch files we expect to exist
if [ ! -e ~/.ssh/config ]; then touch ~/.ssh/config; fi
if [ ! -e ~/.ssh/known_hosts ]; then touch ~/.ssh/known_hosts; fi

# Parse ~/.ssh/known_hosts and ~/.ssh/config to find hosts
for x in `sed -e ’s/[, ].*//’ ~/.ssh/known_hosts; awk ‘/^Host [^*?]+$/{print $2}’ ~/.ssh/config`; do

# Don’t override commands
type $x > /dev/null 2>&1 && continue
alias $x=”ssh $x”

# Remove the domainname
y=${x/.*/}
if [ “$y” != “$x” ]; then
if ! type $y > /dev/null 2>&1; then
alias $y=”ssh $x”
fi
fi

# Remove prefix. Add prefixes you want removed here
y=${y/pf1-/}
y=${y/pf2-/}
if [ “$y” != “$x” ]; then
if ! type $y > /dev/null 2>&1; then
alias $y=”ssh $x”
fi
fi
done
fi


Posted

in

by

Tags: