Wednesday 14 October 2009

Select loop in Shell

print 'Select your terminal type:'


PS3='terminal? '
select term in \
'Givalt VT100' \
'Tsoris VT220' \
'Shande VT320' \
'Vey VT520'
do
case $REPLY in
1 ) TERM=gl35a ;;
2 ) TERM=t2000 ;;
3 ) TERM=s531 ;;
4 ) TERM=vt99 ;;
* ) print 'invalid.' ;;
esac
if [[ -n $term ]]; then
print TERM is $TERM
break
fi
done


Sample script I am using to login to ips:

#!/bin/bash

select ip in '172.43.180.36' '172.43.180.35' 120 121 142 225 230 224 170 112 141 220 208 203 206 75 76 77 232 ;
do
[[ $ip -ne "172.43.180.36" || $ip -ne "172.43.180.35" ]] && ssh root@172.43.0.$ip || ssh root@$ip ;
trap "exit" 0 3 ;
done

O/p:
./select.sh
1) 172.43.180.36 6) 225 11) 141 16) 75
2) 172.43.180.35 7) 230 12) 220 17) 76
3) 120 8) 224 13) 208 18) 77
4) 121 9) 170 14) 203 19) 232
5) 142 10) 112 15) 206
#?1


Note:Selecting 1 logs into 1) ip address using ssh.

No comments:

Post a Comment

Tweets by @sriramperumalla