多开发机别名跳转脚本片段

#! /bin/bash

# @author
# @breif  auto ssh 

function show_usage(){
   echo -e "=================This is Usage====="
   echo -e "          -h:   which host to go,for example dev041"
}

function show_hostlist(){
    echo "dev357  => xxxxx" 
    echo "45      => xxxxx"
}

function ssh_fun(){
   if [ $# -ne 1 ];then
       show_hostlist
   fi
   
   case "$1" in
       "a"        ) ssh zhaoyixing@x.xxxx.com ;;
       "b"        ) ssh zhaoyixing@x.xxxxx            ;;
       "*"        ) ssh $1 ;;
   esac
   
}

#ssh 

if [ $# -eq 0 ];then
    echo -e "\e[1;31mParams Error:\e[0m MayBe You Need Use -h"    
    show_usage
    exit 0 
fi


#1.The ":" after h  mean that h can take values
#2.$OPTARG contains current value

host=''
while getopts "h:"  Option;do
    case $Option in
        h)ssh_fun $OPTARG ;;
        *)show_usage ;;
    esac
done

  

posted on 2021-04-17 12:05  DeNiro  阅读(35)  评论(0编辑  收藏  举报

导航