shell 二维数组

主要通过shell的二维数组 跳入指定服务器
当输入0的时候 连接mongo数据库
可以针对 多个服务器部署

echo "服务器操作列表"
color[0]='\033[37m'
color[1]='\033[31m'
color[2]='\033[32m'
color[3]='\033[33m'
color[4]='\033[34m'
color[5]='\033[35m'
color[6]='\033[36m'
color[7]='\033[30m'
color[8]='\033[30m'

service[0]='mongo'
service[1]='project1'
service1[0]='192.168.1.1'
service1[1]='192.168.1.2'
service[2]='project2'
service2[0]='192.168.2.1'
service2[1]='192.168.3.1'

service[3]='project3'
service3[0]='192.168.4.1'
service3[1]='192.168.5.1'


function gotoSsh(){
     eval value=(\${service${1}[@]})
     for (( i = 0; i < ${#value[@]} ; ++i )); 
    do 
        echo -e ${color[i]} "[$i] == ${value[$i]}"
    done
    echo -e "\033[0m"  
    read -p "请选择服务器:   " num 
    ssh ${value[$num]}

}

for (( i = 0; i < ${#service[@]}; ++i )); 
do 
    echo -e ${color[i]} "[$i]  =  ${service[i]}   "; 
done  
echo -e "\033[0m"  
read -p "请选择操作:   " key
if [ $key -eq '0' ]
then
    mongo localhost:20120/mongodb -u test -p 123456 
else
    gotoSsh $key
fi


你可能感兴趣的:(shell)