一、expect形式
1.安装expect
yum install expect -y
2.Expect脚本
#!/usr/bin/expect
set ip 10.0.0.149
set user yangchenghua
set password yangchenghua
set timeout 10
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
interact
二、shell形式
#!/bin/bash
ip=10.0.0.7
user=root
password=********
expect <<EOF
set timeout 20
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
expect eof
EOF
标签:脚本,shell,send,expect,yes,password,user From: https://www.cnblogs.com/yangchenghua/p/16659855.html