Re: reading Expect buffer and taking out certain information



On Mar 8, 10:33 pm, brickwalls19 <brickwall...@xxxxxxxxx> wrote:
Need assistance in removing the cobwebs from my eyes.

I'm using Expect to grab a switch's output. I wish to extract the
hostname and IP address.

Switch's output:
Port (Our Port): 16/1
Device ID: myrouter
Device Addresses:
IP Address: 10.50.50.1
Holdtime: 159 sec
Capabilities: ROUTER

1. What's best to read the expect_out buffer line by line to match the
2 variables I wish to get? I was thinking a while loop and try and
read each line one at a time.

<log into switch>
send "show cdp neigh detail\r"
<switch begins output of command. how best to process the expect
buffer?>

2. Thinking of incorporating regexp. Using "expect" command doesn't
seem correct since I want to grab more than 1 information.

regexp {ID: (\[^\r\n]*)\r\n} $expect_out(0,string) NeighDevice
regexp {IP Address: (\[^\r\n]*)\r\n} $expect_out(0,string)
NeighAddress

Thanks.

The clue is that you have name value pairs split up by ':' character
use
array set data {}

expect {
-re {^([^:])+:(.*)$} {
set data($expect_out(0,string)) $expect_out(1,string)
exp_continue;
}
timeout {
.



Relevant Pages

  • Re: Emails stuck in queue error 451 4.4.0 Primary target IP addres
    ... If you had just said "Siv you forgot to include the port number in the ... Telnet command" in your first response after asking me to carry out the ... I said earlier I am not familiar with telnet, I have probably used it twice ... Connecting To smtp.surfdsl.net...Could not open connection to the host, ...
    (microsoft.public.exchange.misc)
  • Re: Cant read a lonely (char)13 from serialport
    ... > 1) I writea command to the port ... >is sent back in response to the command that I sent. ... remote device might be accepting a command, ... and wait for an *appropriate* response before ...
    (comp.os.linux.development.system)
  • RE: ppp confusion
    ... tun0: Warning: papchap:: Invalid command ... acpi0: power button is handled as a fixed feature programming model. ... pcib0: port ...
    (freebsd-questions)
  • Re: LPT1 Port Prints to Network Printer
    ... Open a Command Prompt and key the command: ... LPT1 Port Prints to Network Printer ...
    (microsoft.public.win2000.printing)
  • Re: WANTED: "BASIC Forum" References
    ... The software used to drive a UART board cassette tape system  is ... Consider  first the problem of writing data to a cassette  tape. ... one a status port, ... use for the WAIT command. ...
    (comp.os.cpm)