/ Published in: Bash

A bash script that auto register ssh aliases of known hosts (as seen at http://blogs.ubuntu-nl.org/dennis/2008/07/29/traincoding-ssh-aliases/).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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
Comments
