zoukankan      html  css  js  c++  java
  • 使用shell脚本自定义实现选择登录ssh

    在系统bin目录中建立两个脚本分别是pssh tssh

    pssh

    #!/usr/bin/expect -f
    set ip [lindex $argv 0 ]
    set port [lindex $argv 1 ]
    set password [lindex $argv 2 ]
    set uname [lindex $argv 3 ] set timeout
    10 spawn ssh root@$ip -p$port expect { "*yes/no" { send "yes "; exp_continue} "*password:" { send "$password clear 请小心使用,您现在登录的服务器IP是:$ip,服务器名称是:$uname" } } interact

    tssh

    #!/bin/sh
    echo "以下是你的所有服务器列表"
    echo "1.A服务器 192.168.100.11"
    echo "2.B服务器 192.168.100.12"
    echo "3.C服务器 192.168.100.13"
    echo "回车键退出"
    echo "请输入对应数字,选择你要登录的服务器:c"
    read input
    test $input = 0
    
    case $input in
    1)pssh 192.168.100.11 22 123456 A服务器;;
    2)pssh 192.168.100.12 22 admin B服务器;;
    3)pssh 192.168.100.13 22 root C服务器;;
    esac

    记得将给脚本加上可执行权限

    然后在终端上执行tssh出现如下结果

    以下是你的所有服务器列表
    1.A服务器 192.168.100.11
    2.B服务器 192.168.100.12
    3.C服务器 192.168.100.13
    回车键退出
    请输入对应数字,选择你要登录的服务器:1
    spawn ssh root@192.168.100.11 -p22
    CentOS release 6.8 (Final)
    Kernel on an m
    root@192.168.100.11's password:
    Last login: Thu Aug 18 18:34:58 2016 from 192.168.100.2

    Welcome to aliyun Elastic Compute Service!

    [root@Official ~]#

  • 相关阅读:
    从Mysql中取出数据并用jieba统计词频
    关于important的用法
    Spring boot主启动类探究
    PHPMyadmin 配置多个网段
    Perl 对json的过滤脚本
    Perl 校验命中的脚本
    web渗透测试工具—Fiddler(转)
    PerlIde in NetBeans7.3 for Debian
    Perl last和next的用法区别
    2020.7.25
  • 原文地址:https://www.cnblogs.com/xiaozong/p/5785097.html
Copyright © 2011-2022 走看看