双层跳板机登录服务器-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\r"}

# 选择跳板机
expect "Select server:*" {send "$server\r"}

# ssh 目标机器 输入帐户名 密码
expect "*$jumphost*" { send "ssh -p $port $usr@$host\r" }
expect "*assword:*" {send "$password\r"}

# 保持交互状态,并把控制权交给控制台
expect "*$host*"; interact
相关文章
相关标签/搜索