[SOLVED] Flushing expect_out(buffer) inside a loop

Greetings,

Having an issue with the expect_out(buffer). in a foreach loop through some switches I am grabbing some arp table information and writing it out to output files (1 each for each switch looped through).

The first iteration works fine. the second iteration of the loop writes the output of the first and second switch. Have tried everyway imaginable to me to flush the expect_out(buffer) after each pass.

Question: How to flush the expect_out(buffer) at the end of the loop before lit begins the next loop?
Below is current code.
TIA

foreach fname {10.x.x.x 11.x.x.x 12.x.x.x} {
match_max 100000
log_user 0
spawn telnet $fname
expect -re "Login"
send "account name\n"
expect -re "Password"
send "password\n"
expect  "*>"
send  "config cli more false\r"
expect  "*>"
send  "show ip arp info\r"
set newlinechar "\r"
set fh [open $fname.txt w]
expect {
 $newlinechar {append arpout $expect_out(buffer); exp_continue}
  eof { append arpout $expect_out(buffer) }
}
puts $fh $arpout
close $fh
expect "somethingnotfound"
expect *
expect eof
}

Solved:
removing the
expect "somethingnotfound"
expect *
and simply setting the arpout variable to blank solved the issue so the end of the code now looks like.

}
puts $fh $arpout
close $fh
set timeout 1
set arpout 1 <-  setting to just a number clears the variable and prints 
                  #   only a 1 which gets filtered out in another script.
}
2 Likes