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.

2
  • Is telnet a must? What if you just do echo 'power_status ?' | nc 10.92.177.14 53595? Do you get "on" in response? Commented Feb 14 at 19:27
  • That command just returns NOKEY. I'd be happy to use netcat instead but I need to figure out how to use it with expect.
    – Elliott B
    Commented Feb 14 at 20:26

0

You must log in to answer this question.

Browse other questions tagged .