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