Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using expect to test as text-based menu

238 views
Skip to first unread message

Reagan

unread,
Mar 15, 2010, 1:25:15 PM3/15/10
to
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

unread,
Mar 16, 2010, 2:23:09 PM3/16/10
to
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.


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

qadi...@gmail.com

unread,
Jul 13, 2018, 8:16:48 AM7/13/18
to
Thanks for mentioning exp_internal 1. very helpful to debug :)

Uwe Klein

unread,
Jul 13, 2018, 8:49:08 AM7/13/18
to
Am 13.07.2018 um 14:16 schrieb qadi...@gmail.com:
>> spawn ssh -Y root@$ipaddr
>> expect "*?assword:*"
^^^^^^^^^^^^this will return when the ":" is received.
( * selects for 0...infinite number of characters)
most pwd dialog has a space after the ":"
you may run into sending the pwd before the system
is ready to receive it.

>> send -- "$password\r"
>>
>> sleep .5
>>
>> expect "Disconnect
>> Calibrate >
>> Utilities >
>> Configuration >
>> Parameters >
>> Processing >
>> System Passwords >
>> Diagnostics >
>> About
>> Save Changes\r"

is expecting the "Disconnect .... Save Changes\r" actually successful?
add some debug output to it to be sure.

Uwe
0 new messages