From: Reagan on
Hi there,

I am fairly new to expect. I have been using it to automate some
testing and have recently run into an issue that I cannot figure out.

I have a text based menu system which is navigable via arrow keys ...
I can log into the system and see the menu however, I cannot figure
out how to send commands to the menu in expect mode.

========================================
My environment is as follows:
expect 5.43.0 on Ubuntu 2.6.24-24 with tcl 8.4
========================================

My menu looks like this:
Disconnect
Calibrate >
Utilities >
Configuration >
Parameters >
Processing >
System Passwords >
Diagnostics >
About
Save Changes

I have an expect script that can ssh into this system and "expect" the
above menu. However, I cannot send it any control characters for
example, the down arrow or "\033\[B".

Here is the script that I am currently working with:

#!/usr/bin/expect -f

set env(TERM) vt100

set password 123abc
set ipaddr 172.18.123.200

set timeout -1
match_max -d 100000

spawn ssh -Y root@$ipaddr
expect "*?assword:*"
send -- "$password\r"

sleep .5

expect "Disconnect
Calibrate >
Utilities >
Configuration >
Parameters >
Processing >
System Passwords >
Diagnostics >
About
Save Changes\r"

# trying to send return followed by "y" and return which should simply
disconnect from the client
send -- "\ry\r"

# down arrow arrow
#send -- "\033\[B"

# up arrow
#send -- "\033\[A"
# back arrow
#send -- "\033\[D"

Note if I take out the expect "Disconnect ... statement above and put
in an interact statement like the one that follows I can get this to
work. I.e., with the below code when I hit a CRTL-A a return y return
will be sent to my process and it will disconnect.

set CTRLZ \032
set CTRLC \003
set CTRLA \001
interact {
-reset $CTRLZ {exec kill -STOP [pid]}
$CTRLA {
exp_send "menucmd...\ry\r"
}
~~
}

My stumbling block is, how do I get this to work with out interact
mode i.e., I want this all scripted / automated.

thanks in advance for any suggestion / assistance!
-reagan
From: Glenn Jackman on
Not an answer specifically to your question, but while you're
developing, add:
exp_internal 1
after your spawn command. That will allow you to see what expect sees,
and you can diagnose your expect misses.


At 2010-03-15 01:25PM, "Reagan" wrote:
> Hi there,
>
> I am fairly new to expect. I have been using it to automate some
> testing and have recently run into an issue that I cannot figure out.
>
> I have a text based menu system which is navigable via arrow keys ...
> I can log into the system and see the menu however, I cannot figure
> out how to send commands to the menu in expect mode.
>
> ========================================
> My environment is as follows:
> expect 5.43.0 on Ubuntu 2.6.24-24 with tcl 8.4
> ========================================
>
> My menu looks like this:
> Disconnect
> Calibrate >
> Utilities >
> Configuration >
> Parameters >
> Processing >
> System Passwords >
> Diagnostics >
> About
> Save Changes
>
> I have an expect script that can ssh into this system and "expect" the
> above menu. However, I cannot send it any control characters for
> example, the down arrow or "\033\[B".
>
> Here is the script that I am currently working with:
>
> #!/usr/bin/expect -f
>
> set env(TERM) vt100
>
> set password 123abc
> set ipaddr 172.18.123.200
>
> set timeout -1
> match_max -d 100000
>
> spawn ssh -Y root@$ipaddr
> expect "*?assword:*"
> send -- "$password\r"
>
> sleep .5
>
> expect "Disconnect
> Calibrate >
> Utilities >
> Configuration >
> Parameters >
> Processing >
> System Passwords >
> Diagnostics >
> About
> Save Changes\r"
>
> # trying to send return followed by "y" and return which should simply
> disconnect from the client
> send -- "\ry\r"
>
> # down arrow arrow
> #send -- "\033\[B"
>
> # up arrow
> #send -- "\033\[A"
> # back arrow
> #send -- "\033\[D"
>
> Note if I take out the expect "Disconnect ... statement above and put
> in an interact statement like the one that follows I can get this to
> work. I.e., with the below code when I hit a CRTL-A a return y return
> will be sent to my process and it will disconnect.
>
> set CTRLZ \032
> set CTRLC \003
> set CTRLA \001
> interact {
> -reset $CTRLZ {exec kill -STOP [pid]}
> $CTRLA {
> exp_send "menucmd...\ry\r"
> }
> ~~
> }
>
> My stumbling block is, how do I get this to work with out interact
> mode i.e., I want this all scripted / automated.
>
> thanks in advance for any suggestion / assistance!
> -reagan


--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous