zoukankan      html  css  js  c++  java
  • 双层跳板机登陆服务器-shell脚本实现自动登陆

    #!/usr/bin/expect
    
    ### 两层跳板机版本 ###
    
    set timeout 15
    set jumpusr [lindex $argv 0]
    set jumphost [lindex $argv 1]
    set jumppassword [lindex $argv 2]
    set usr [lindex $argv 3]
    set host [lindex $argv 4]
    set port [lindex $argv 5]
    set password [lindex $argv 6]
    set server [lindex $argv 7]
    
    # ssh 跳板机 输入账户名 密码
    catch {spawn ssh $jumpusr@$jumphost}
    expect "*assword:*" {send "$jumppassword
    "}
    
    # 选择跳板机
    expect "Select server:*" {send "$server
    "}
    
    # ssh 目标机器 输入账户名 密码
    expect "*$jumphost*" { send "ssh -p $port $usr@$host
    " }
    expect "*assword:*" {send "$password
    "}
    
    # 保持交互状态,并把控制权交给控制台
    expect "*$host*"; interact
  • 相关阅读:
    K好数
    蓝桥杯 安慰奶牛
    蓝桥杯 节点选择
    模拟链表
    10588
    八数码的 八种境界
    HIT 2051
    概率DP
    数组越界溢出
    FATFS在SD卡里,写入多行数据出的问题
  • 原文地址:https://www.cnblogs.com/hcy-fly/p/11088910.html
Copyright © 2011-2022 走看看