0

I'm trying to read data from a machine that uses a telnet style interface using expect. An interactive telnet session works like this:

% telnet 10.92.177.14 53595
Trying 10.92.177.14...
Connected to 10.92.177.14.
Escape character is '^]'.
NOKEY
power_status ?
"on"
^]
telnet> Connection closed.

I sent the command power_status ? and get the response "on".

I tried the following expect script:

#!/usr/bin/expect -f

spawn telnet 10.92.177.14 53595 expect -- "NOKEY\r" send "power_status ?\r" interact

It returns this output and remains open:

spawn telnet 10.92.177.14 53595
Trying 10.92.177.14...
Connected to 10.92.177.14.
Escape character is '^]'.
NOKEY
power_status ?
"on"

How can suppress everything but the "on" output, and make it exit afterward? If I remove the interact line then it does exit but I don't see the response.

Elliott B
  • 1,205

0 Answers0