#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress
#expect "yes/no"
#send "yes\r"
expect "password:"
send "$passwd\r"
expect "]*"
send "mkdir -p /tmp/haha/haha2\r"
send "exit\r"
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress
#expect "yes/no"
#send "yes\r"
expect "password:"
send "$passwd\r"
expect "]*"
send "mkdir -p /tmp/haha/haha2\r"
send "exit\r"
***************
expect {
"(yes/no)?" {
send "yes\n"
}
"password:" {
....
}
判断语句
if {$havepass == 0} {
expect "password:" { send "$pw\n" }
}
"(yes/no)?" {
send "yes\n"
}
"password:" {
....
}
判断语句
if {$havepass == 0} {
expect "password:" { send "$pw\n" }
}
或者:
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
转载于:https://blog.51cto.com/verdureorange/134547