雙層跳板機登錄服務器-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
相關文章
相關標籤/搜索