想通过expect send多个不同的密码
以下写的三种方式都试过了,要么卡在第二个不输入了,要么是输入的时机不对。这个该怎么解决? 其实如果能按着我的顺序expect send 密码也行
catch {spawn sh ./xx.sh param1}
# expect "*password:*"
# send "$onlinePass\r"
# expect "*password:*"
# send "$testPass\r"
# expect "*password:*"
# send "$onlinePass\r"
# expect "*password:*"
# send "$testPass\r"
expect {
"*password:*" {
send "$onlinePass\r"
}
"*password:*" {
send "$testPass\r"
}
"*password:*" {
send "$onlinePass\r"
}
"*password:*" {
send "$testPass\r"
}
}
# expect {
# "*password:*" {
# send "$testPass\r"
# }
# }
# expect {
# "*password:*" {
# send "$onlinePass\r"
# }
# }
# expect {
# "*password:*" {
# send "$testPass\r"
# }
# }
已经找到问题所在了,原因是expect超时,默认expect是10秒,由于shell中是mysqldump所以时间会比较长,导致后续的expect超时等待,所以加上set timeout 120就可以了。