Hi 你好,欢迎访问!登录
当前位置:首页 - Linux - 正文 忍人所不忍,能人所不能。

shell终端登陆linux脚本

2020-02-08Linux90root188°c
A+ A-
在做运维的过程中,如果服务器多,挨个登陆太费劲了,不如写个脚本来的实在。只需要把IP加入到脚本内,跳板机和服务器进行公钥私钥认证,即可实现免密登陆。
[email protected]:~$ cat connect.sh
#!/bin/bash
#about: 90root
#date : 20160518
#定义主机
bj1=xx.xx.xx.xx
bj2=xx.xx.xx.xx
bj3=xx.xx.xx.xx
hz1=xx.xx.xx.xx
bj4=xx.xx.xx.xx
lan40=172.168.200.140
lan43=172.168.200.143
lan51=172.168.200.151
docker_210=172.168.200.210
docker_211=172.168.200.211
docker_212=172.168.200.212
docker_213=172.168.200.213
function display(){
    echo "\033[32m---------------\033[0m"
    echo "\033[32m1. ssh wan hosts\033[0m"
    echo "\033[32m2. ssh lan hosts\033[0m"
    echo "\033[32m3. ssh lan docker\033[0m"
    echo "\033[32m4. exit\033[0m"
    echo "\033[32m---------------\033[0m"
}
function wan(){
echo "\033[32m-----------\033[0m"
echo "\033[32m1. 北京1\033[0m"
echo "\033[32m2. 北京2\033[0m"
echo "\033[32m3. 北京3\033[0m"
echo "\033[32m4. 杭州3\033[0m"
echo "\033[32m5. 上一层\033[0m"
echo "\033[32m6. 退出\033[0m"
echo "\033[32m-----------\033[0m"
}
function lan(){
echo "\033[32m-----------\033[0m"
echo "\033[32m1. 201\033[0m"
echo "\033[32m2. vpn-43\033[0m"
echo "\033[32m3. Docker-200\033[0m"
echo "\033[32m4. 上一层\033[0m"
echo "\033[32m5. 退出\033[0m"
echo "\033[32m-----------\033[0m"
}
function timecash(){
echo "\033[32m-----------\033[0m"
echo "\033[32m1. new_bj1\033[0m"
echo "\033[32m2. new_bj2\033[0m"
echo "\033[32m3. new_bj3\033[0m"
echo "\033[32m4. new_hz1\033[0m"
echo "\033[32m5. new_bj4\033[0m"
echo "\033[32m6. 上一层\033[0m"
echo "\033[32m7. 退出\033[0m"
echo "\033[32m-----------\033[0m"
}
function docker(){
echo "\033[32m-----------\033[0m"
echo "\033[32m1. Docker-210\033[0m"
echo "\033[32m2. Docker-211\033[0m"
echo "\033[32m3. Docker-212\033[0m"
echo "\033[32m4. Docker-213\033[0m"
echo "\033[32m5. 上一层\033[0m"
echo "\033[32m6. 退出\033[0m"
echo "\033[32m-----------\033[0m"
}
function input1(){
    while True;do
    display
    read -p "please input number: " num
    expr $num + 1 &> /dev/null
    if [ $? -eq 0 ];then
        if [ $num -eq 1 ];then
            while True;do
                wan
            read -p "please input connect server: " wan_server
            case $wan_server in
            1)
                ssh [email protected]$bj1
                exit
                ;;
            2)
                ssh [email protected]$bj2
                exit
                ;;
            3)
                ssh [email protected]$bj3
                exit
                ;;
            4)
                ssh [email protected]$hz3
                exit
                ;;
            5)
                break
                display
                ;;
            6)
                exit
                ;;
            *)
                echo "\033[31mPlease input effective number\033[0m"
                ;;
            esac
            done
        elif [ $num -eq 2 ];then
            while True;do
               lan
               read -p "please input connect server: " lan_server
               case $lan_server in
               1)
                   ssh [email protected]$lan40
                   exit
                   ;;
               2)
                    ssh [email protected]
                    exit
                    ;;
               3)
                    ssh [email protected]$lan51
                    exit
                    ;;
               4)
                    break
                    display
                    ;;
               5)
                   exit
                   ;;
               *)
                   echo "\033[31mPlease input effective number\033[0m"
                   ;;
               esac
            done
        elif [ $num -eq 3 ];then
            while True;do
            docker
            read -p "please input connect server: " docker_server
            case $docker_server in
            1)
                ssh [email protected]$docker_210
                exit
                ;;
            2)
                ssh [email protected]$docker_211
                exit
                ;;
            3)
                ssh [email protected]$docker_212
                exit
                ;;
            4)
                ssh [email protected]$docker_213
                exit
                ;;
            5)
                break
                display
                ;;
            6)
                exit
                ;;
            *)
                echo "\033[31mPlease input effective number\033[0m"
                ;;
            esac
           done
        elif [ $num -eq 4 ];then
            exit
        else
            echo "\033[31mPlease input effective number\033[0m"
        fi
    else
        echo "\033[31mInput error, Please input number\033[0m"
    fi
    done
}
input1
  移步手机端
shell终端登陆linux脚本

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签:

发表评论

选填

必填

必填

选填

请拖动滑块解锁
>>


  用户登录