#!/usr/bin/expect ### 新版双层跳板机版本 ### # 设置15秒超时时间 set timeout 15 # 设置参数名称 set jumpusr [lindex $argv 0] set jumphost [lindex $argv 1] set jumppassword [lindex $argv 2] set jumpid [lindex $argv 3] set jumpcmd [lindex $argv 4] set host [lindex $argv 5] set port [lindex $argv 6] set password [lindex $argv 7] # ssh 第一层跳板机 输入密码 catch {spawn ssh $jumpusr@$jumphost} expect "*assword:*" {send "$jumppassword "} # 选择第二层跳板机 并选择手动输入命令 expect "请选择目标资产:*" {send "$jumpid "} expect "请输入命令或服务器ID:*" {send "$jumpcmd "} # 输入目标ip和port expect "IP:*" {send "$host "} expect "Port:*" {send "$port "} # 输入目标ip的密码 expect "*assword:*" {send "$password "} # 保持交互状态,并把控制权交给控制台 expect "*$host*"; interact # demo # houcaiyun fort.xxxx.co password1 1 m 目标ip port 目标ip的密码