Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing expect_out buffer

Status
Not open for further replies.

JackLevin

Technical User
Oct 18, 2010
1
DE
Hi,

I coded a script in expect. That logs into several switches with different OS versions. The command order I'll execute on the switches depends on its OS version. E.g. it looks like, when I log into different OS:

=============================
Escape character is '^]'.


Fabric OS (tm) Release v3.2.1c

login:
=============================
Escape character is '^]'.


Fabric OS (switch)
Fabos Version 5.3.0c


switch login:
=============================

The idea was to parse the lines on "3.2.1" or "5.3.0". Does anyone can help me on that task? I tried already simple things like:

expect {
"3.2.1" { .. }
"5.3.0" { .. }
}

But that doesn' work. I assume, because the key string is not in the last line. My last idea was to do something like:

spawn telnet $hostname
expect "login: " {send "$user\r"}
expect "Password:" {send "$password1\r"}

append output "$expect_out(buffer)"

set timeout 50
if [ string match "*3.2.1*" $expect_out(buffer) ] {
}
else if [ string match "*5.3.0*" $expect_out(buffer) ]
}

But doesn't work as well. Any other ideas on how to make the fork?

Cheers,
Jack
 
I don't know any EXPECT but what do see if you query the contents of "expect_out(buffer)"?

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top