Skip to content

Instantly share code, notes, and snippets.

@lbarulski
Created May 15, 2013 17:37
Show Gist options
  • Save lbarulski/5585785 to your computer and use it in GitHub Desktop.
Save lbarulski/5585785 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ -n "$*" ];
then
if [ "$*" == "--help" ] || [ "$*" == "-h" ];
then
echo $0 '[username]';
exit;
fi
user="$*";
else
user=`whoami`;
fi
hosts=`cat ~/.ssh/known_hosts | awk '{ print $1 }' | awk -F"," '{ gsub(/\[|\]/, "", $1); gsub(/\:/, " -p ", $1); gsub(/$/, ",", $1); print $1 }'`
hosts=`echo $hosts | sed 's/, /,/g'`
OLD_IFS="$IFS"
IFS=","
hosts=( $hosts )
IFS="$OLD_IFS"
echo -e "\\033[32m### Choose one of them: ###\\033[0m"
for (( i=0; $i<${#hosts[@]}; i++ ))
do
echo -e "\\033[1m${i}\\033[0m"\) "\\033[36m${user}\\033[0m""\\033[33m@\\033[0m"${hosts[$i]}
done
echo
read -p "Your choose: " number
if [ -n "${hosts["$number"]}" ];
then
ssh ${user}@${hosts[$number]} -A
else
echo 'Out of range!';
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment