Linux 如何处理不同的Expect消息?
需要有编写expect脚本经验的人的帮助。我无法找到正确的解决方案来处理expect脚本中返回的多种类型的消息。我试图测试两个场景,其中返回的最终消息可能有两种不同类型的响应。除了处理该响应外,不希望为最终的回显消息发送任何响应。我如何做到这一点Linux 如何处理不同的Expect消息?,linux,bash,shell,expect,Linux,Bash,Shell,Expect,需要有编写expect脚本经验的人的帮助。我无法找到正确的解决方案来处理expect脚本中返回的多种类型的消息。我试图测试两个场景,其中返回的最终消息可能有两种不同类型的响应。除了处理该响应外,不希望为最终的回显消息发送任何响应。我如何做到这一点 test_script.sh --------------- #!/bin/bash echo "Session Name ?" read $REPLY echo "First Name ?" read $REPLY echo "Last Nam
test_script.sh
---------------
#!/bin/bash
echo "Session Name ?"
read $REPLY
echo "First Name ?"
read $REPLY
echo "Last Name ?"
read $REPLY
echo "Op# ?"
read $REPLY
echo "Password ?"
read $REPLY
echo "Password again?"
read $REPLY
echo "Session Name: RajP"
echo "First Name : Raj"
echo "Last Name : P"
echo "OP# : Arch"
echo "Continue? (y|n)"
read $REPLY
echo "row count = 1"
test_script2.sh
---------------
#!/bin/bash
echo "Session Name ?"
read $REPLY
echo "First Name ?"
read $REPLY
echo "Last Name ?"
read $REPLY
echo "Op# ?"
read $REPLY
echo "Password ?"
read $REPLY
echo "Password again?"
read $REPLY
echo "Session Name: RajP"
echo "First Name : Raj"
echo "Last Name : P"
echo "OP# : Arch"
echo "Continue? (y|n)"
read $REPLY
echo "You already have a ses_data record for OP_NBR=Arch"
expect_test_script.sh
---------------------
#!/usr/bin/expect -f
set timeout -1
spawn ./test_script.sh
expect "Session Name ?\r"
send "RajP\r"
expect "First Name ?\r"
send "Raj\r"
expect "Last Name ?\r"
send "P\r"
expect "Op# ?\r"
send "Arch\r"
expect "Password ?\r"
send "Pass123\r"
expect "Password again?\r"
send "Pass123\r"
expect "Session Name: RajP\r"
expect "First Name : Raj\r"
expect "Last Name : P\r"
expect "OP# : Arch\r"
expect "Continue? (y|n)\r"
send "y\r"
expect {
"You already have a ses_data record for OP_NBR=Arch"{exp_continue}
"row count = 1"{exp_continue}
}
expect eof
My expect script is trying to test 2 different shell scripts : test_script.sh and test_script2.sh ...
It fails with this message
expect: spawn id exp7 not open
while executing
"expect eof"
(file "./expect_test_script.sh" line 26)
如何对expect脚本进行编码,使其能够处理两个测试脚本(test_script.sh和test_script2.s)的最后一次回显?没关系。。。这是expect脚本中的错误。这把它修好了
expect {
"You already have a ses_data record for OP_NBR=Arch" {}
"row count = 1" {}
}
expect eof
没关系。。。这是expect脚本中的错误。这把它修好了
expect {
"You already have a ses_data record for OP_NBR=Arch" {}
"row count = 1" {}
}
expect eof