bash - Using expect multiple times in /usr/bin/expect -
i'm trying automate calls message oriented middleware application called disque using disque , i'm running difficulty...
everytime want client run command, must expect prompt gives , send command, when try more once, run problems.
here expect script in basic non-functioning form:
set timeout 20 spawn "./disque" set timeout 10 expect "127.0.0.1:7711> " {send "addjob scriptqueue body 0\r"} set timeout 10 expect "127.0.0.1:7711> " {send "getjob scriptqueue\r"}
however, when run above script, first prompt read , first message sent. getjob command never run.
here output get:
spawn ./disque 127.0.0.1:7711> addjob scriptqueue body 0
also reference, how disque works when manually input 2 strings when i'm prompted:
127.0.0.1:7711> addjob scriptqueue body 0 di530404a85743c0afe1353ae1943df8d86c9f561005a0sq 127.0.0.1:7711> getjob scriptqueue 1) 1) "scriptqueue" 2) "di530404a806ff88886c366ba3566d7e36ea81f89605a0sq" 3) "body" 127.0.0.1:7711>
update:
i ran script using -d debug mode , got output:
expect version 5.45 argv[0] = expect argv[1] = -d argv[2] = cng4.sh set argc 0 set argv0 "cng4.sh" set argv "" executing commands command file cng4.sh spawn ./disque parent: waiting sync byte parent: telling child go ahead parent: unsynchronized child spawn: returns {17657} expect: "" (spawn_id exp4) match glob pattern "*>"? no 127.0.0.1:7711> expect: "127.0.0.1:7711> " (spawn_id exp4) match glob pattern "*>"? yes expect: set expect_out(0,string) "127.0.0.1:7711>" expect: set expect_out(spawn_id) "exp4" expect: set expect_out(buffer) "127.0.0.1:7711>" send: sending "addjob scriptqueue body 0\r" { exp4 } expect: " " (spawn_id exp4) match glob pattern "*>"? no 127.0.0.1:7711> addjob scriptqueue body 0 di530404a8efd0d77b5bb62a7568510f7b6a29a13405a0sq 127.0.0.1:7711> expect: " \r\u001b[0k127.0.0.1:7711> a\r\u001b[17c\r\u001b[0k127.0.0.1:7711> ad\r\u001b[18c\r\u001b[0k127.0.0.1:7711> add\r\u001b[19c\r\u001b[0k127.0.0.1:7711> addj\r\u001b[20c\r\u001b[0k127.0.0.1:7711> addjo\r\u001b[21c\r\u001b[0k127.0.0.1:7711> addjob\r\u001b[22c\r\u001b[0k127.0.0.1:7711> addjob \r\u001b[23c\r\u001b[0k127.0.0.1:7711> addjob s\r\u001b[24c\r\u001b[0k127.0.0.1:7711> addjob sc\r\u001b[25c\r\u001b[0k127.0.0.1:7711> addjob scr\r\u001b[26c\r\u001b[0k127.0.0.1:7711> addjob scri\r\u001b[27c\r\u001b[0k127.0.0.1:7711> addjob scrip\r\u001b[28c\r\u001b[0k127.0.0.1:7711> addjob script\r\u001b[29c\r\u001b[0k127.0.0.1:7711> addjob scriptq\r\u001b[30c\r\u001b[0k127.0.0.1:7711> addjob scriptqu\r\u001b[31c\r\u001b[0k127.0.0.1:7711> addjob scriptque\r\u001b[32c\r\u001b[0k127.0.0.1:7711> addjob scriptqueu\r\u001b[33c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue\r\u001b[34c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue \r\u001b[35c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue b\r\u001b[36c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue bo\r\u001b[37c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue bod\r\u001b[38c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body\r\u001b[39c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body \r\u001b[40c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body 0\r\u001b[41c\r\ndi530404a8efd0d77b5bb62a7568510f7b6a29a13405a0sq\r\n127.0.0.1:7711> " (spawn_id exp4) match glob pattern "*>"? yes expect: set expect_out(0,string) " \r\u001b[0k127.0.0.1:7711> a\r\u001b[17c\r\u001b[0k127.0.0.1:7711> ad\r\u001b[18c\r\u001b[0k127.0.0.1:7711> add\r\u001b[19c\r\u001b[0k127.0.0.1:7711> addj\r\u001b[20c\r\u001b[0k127.0.0.1:7711> addjo\r\u001b[21c\r\u001b[0k127.0.0.1:7711> addjob\r\u001b[22c\r\u001b[0k127.0.0.1:7711> addjob \r\u001b[23c\r\u001b[0k127.0.0.1:7711> addjob s\r\u001b[24c\r\u001b[0k127.0.0.1:7711> addjob sc\r\u001b[25c\r\u001b[0k127.0.0.1:7711> addjob scr\r\u001b[26c\r\u001b[0k127.0.0.1:7711> addjob scri\r\u001b[27c\r\u001b[0k127.0.0.1:7711> addjob scrip\r\u001b[28c\r\u001b[0k127.0.0.1:7711> addjob script\r\u001b[29c\r\u001b[0k127.0.0.1:7711> addjob scriptq\r\u001b[30c\r\u001b[0k127.0.0.1:7711> addjob scriptqu\r\u001b[31c\r\u001b[0k127.0.0.1:7711> addjob scriptque\r\u001b[32c\r\u001b[0k127.0.0.1:7711> addjob scriptqueu\r\u001b[33c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue\r\u001b[34c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue \r\u001b[35c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue b\r\u001b[36c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue bo\r\u001b[37c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue bod\r\u001b[38c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body\r\u001b[39c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body \r\u001b[40c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body 0\r\u001b[41c\r\ndi530404a8efd0d77b5bb62a7568510f7b6a29a13405a0sq\r\n127.0.0.1:7711>" expect: set expect_out(spawn_id) "exp4" expect: set expect_out(buffer) " \r\u001b[0k127.0.0.1:7711> a\r\u001b[17c\r\u001b[0k127.0.0.1:7711> ad\r\u001b[18c\r\u001b[0k127.0.0.1:7711> add\r\u001b[19c\r\u001b[0k127.0.0.1:7711> addj\r\u001b[20c\r\u001b[0k127.0.0.1:7711> addjo\r\u001b[21c\r\u001b[0k127.0.0.1:7711> addjob\r\u001b[22c\r\u001b[0k127.0.0.1:7711> addjob \r\u001b[23c\r\u001b[0k127.0.0.1:7711> addjob s\r\u001b[24c\r\u001b[0k127.0.0.1:7711> addjob sc\r\u001b[25c\r\u001b[0k127.0.0.1:7711> addjob scr\r\u001b[26c\r\u001b[0k127.0.0.1:7711> addjob scri\r\u001b[27c\r\u001b[0k127.0.0.1:7711> addjob scrip\r\u001b[28c\r\u001b[0k127.0.0.1:7711> addjob script\r\u001b[29c\r\u001b[0k127.0.0.1:7711> addjob scriptq\r\u001b[30c\r\u001b[0k127.0.0.1:7711> addjob scriptqu\r\u001b[31c\r\u001b[0k127.0.0.1:7711> addjob scriptque\r\u001b[32c\r\u001b[0k127.0.0.1:7711> addjob scriptqueu\r\u001b[33c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue\r\u001b[34c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue \r\u001b[35c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue b\r\u001b[36c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue bo\r\u001b[37c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue bod\r\u001b[38c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body\r\u001b[39c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body \r\u001b[40c\r\u001b[0k127.0.0.1:7711> addjob scriptqueue body 0\r\u001b[41c\r\ndi530404a8efd0d77b5bb62a7568510f7b6a29a13405a0sq\r\n127.0.0.1:7711>" send: sending "getjob scriptqueue\r" { exp4 }
it looks reason it's picking other output disque application itself...i'm still not sure how solve this.
thanks.
as can see debug log, getjob
sent application. problem did not wait getjob
finish. think how know getjob
has finished when manually interact application? wait next prompt, right? tell expect
same thing. that's say, tell expect
wait next prompt before moves on (or exit).
expect "127.0.0.1:7711> " {send "getjob scriptqueue\r"} expect "127.0.0.1:7711> "
Comments
Post a Comment