expect 脚本send 多个不同的密码?

想通过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"
#        }
#    }
阅读 2.1k
1 个回答

已经找到问题所在了,原因是expect超时,默认expect是10秒,由于shell中是mysqldump所以时间会比较长,导致后续的expect超时等待,所以加上set timeout 120就可以了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进