Re: reading Expect buffer and taking out certain information
- From: Bezoar <cwjolly@xxxxxxxxx>
- Date: Sun, 9 Mar 2008 11:25:34 -0700 (PDT)
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 {
.
- Follow-Ups:
- Re: reading Expect buffer and taking out certain information
- From: Alexandre Ferrieux
- Re: reading Expect buffer and taking out certain information
- References:
- reading Expect buffer and taking out certain information
- From: brickwalls19
- reading Expect buffer and taking out certain information
- Prev by Date: Re: translating .hex file (binary) to ASCII.
- Next by Date: Re: reading Expect buffer and taking out certain information
- Previous by thread: reading Expect buffer and taking out certain information
- Next by thread: Re: reading Expect buffer and taking out certain information
- Index(es):
Relevant Pages
|