可以配合for循环一起使用
#!/usr/bin/expect
if {argc<3} {
puts "Usage:cmd <host> <username> <password>"
exit 1
}
set timeout -1
set host [lindexargv 0]
set username [lindex argv 1]
set password [lindexargv 2]
spawn ssh username@host
# expect "*password*" {send "password\r"}
expect {
"*yes*no*" {
send "yes\r"
exp_continue
}
"*password*" {
send "password\r"
exp_continue
}
"*#*" {
send "exit\r"
exp_continue
}
eof
{
send "eof"
}
}
interact