使用expect实现连接远程跳板机

626 阅读1分钟

expect安装

以mac为例,先安装HomeBrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

接着使用brew命令安装expect

brew install epxect

接着运行如下脚本:

#!/usr/bin/expect
set timeout -1
set username "tomcat"
set password "tomcat"
set host <ip地址>
spawn ssh $username@$host
expect {
  "*assword*" { send "$password\r"; }
  "yes/no" { send "yes\r";exp_continue }
}

interact

博客地址 gitbook小册