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