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

#! /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

  

如果想和我我交流技术方向的心得及感受,可以扫码关注我的公众号,上面我绑定了微信号。
原文地址:https://www.cnblogs.com/zhaoyixing/p/14670376.html