Here’s a quick script I used to create a dynamic menu from a grep command for ssh connections:

server=$1
nodes=`grep -i $server /etc/hosts | awk '{print $2}'`
if [[ $nodes = "" ]];then
  echo "$server not found"
  exit 1
fi
count=0
for node in  `echo $nodes`
do
  item[$count]="$node"
  (( count = count + 1 ))
done
set "${item[@]}"
select n in "$@"
do
  sudo ssh $n
  exit
done

About troyski

I'm a freelance UNIX engineer working in the UK. I'm married to Tina and between us we have six children. I'm a bit of an Apple fan boy, and all the Windows machines in the house are a thing of the past now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation