我有两个简单的脚本,需要使用第三个expect
脚本自动互相交互。
script1.sh
#!/bin/bash
echo "s1: started"
echo "question1"
read
echo "got ${REPLY}"
echo "question2"
read
echo "got ${REPLY}"
echo "question3"
read
echo "got ${REPLY}"
echo "s1: finished"
script2.sh
#!/bin/bash
echo "s2: started"
read
echo "got ${REPLY}"
echo "answer1"
read
echo "got ${REPLY}"
echo "answer2"
read
echo "got ${REPLY}"
echo "answer3"
echo "s2: finished"
auto_s1_s2.exp
#!/usr/bin/expect
spawn -noecho ./script1.sh
set s1ID $spawn_id
spawn -noecho ./script2.sh
set s2ID $spawn_id
expect -i $s1ID "question1" {
send_user "exp: question1\n"
send -i $s2ID "question1\r"
expect -i $s2ID "answer1" {
send_user "exp: answer1\n"
send -i $s1ID "answer1\r"
}
}
interact
运行./auto_s1_s2.exp
的输出如下:
s1: started
question1
exp: question1
question1
s2: started
got question1
answer1
exp: answer1
我希望您能翻译以下内容:
我期望s1
会回应question1
,并通过expect $s1ID "question1"
进行验证,然后expect脚本将发送question1
到s2
,并期望从中接收answer1
,然后将answer
发送到s1
,如此循环。
看起来 answer1
没有被 script1
接收到。
我在这里做错了什么?
script1
does get theanswer1
, but your interact command will not show it. You need to tell it to listen to the spawn id:interact -i $s1ID
- meuh