[SOLVED] Flushing expect_out(buffer) inside a loop


 
Thread Tools Search this Thread
Top Forums Programming [SOLVED] Flushing expect_out(buffer) inside a loop
# 1  
Old 08-31-2012
[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
Code:
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
}

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.


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.
Code:
}
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.
}


Last edited by vbe; 09-04-2012 at 12:00 PM.. Reason: code tagged supersix's solution...
These 2 Users Gave Thanks to SuperSix4 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies

2. Shell Programming and Scripting

Trying to parse expect_out(buffer)

trying to telnet to a device, list the files, and delete them. I can get the script to telnet and log in OK, and even issue the command to list out the files. I can't figure out how to parse the expect_out(buffer) and extract the file name for use in the delete command. the files list out like... (4 Replies)
Discussion started by: imatinkerer
4 Replies

3. Shell Programming and Scripting

Jumbled output in expect_out(buffer)

I have a code like this : set ipv6_acl_max_chars test_acl_max_chars123456a789%s%d2345678ww134rt789qa23456789012345%c89012%a56789012x4r67890test_acl_max_chars1234567890.01234aabcdob34567aBC0 spawn telnet $myip expect "Login:" { send "admin\r" } expect "Password:" {send "admin\r" }... (0 Replies)
Discussion started by: ylucki
0 Replies

4. Programming

Flushing expect_out(buffer)

Can some one tell me how to flush expect_out(buffer)? below is my code expect -re {.*} {} expect "swpackages>*" send -i $con "trial.bat \r" set outcome $expect_out(buffer) expect "*continue*" set prevreport $expect_out(buffer) send "\r \r"; problem is :- I am getting "pre" stuffs... (0 Replies)
Discussion started by: cityprince143
0 Replies

5. Shell Programming and Scripting

Expect_out(buffer) works but it doesn't get all lines

Hello "expect" experts I am new at Expect. I have searched for a little while how to capture multiple lines with Expect and I am almost succeeded on that but I don't get all the lines of a command's output that the script executes on a server. Here is how my script works in a nutshell - ... (6 Replies)
Discussion started by: capacho6666
6 Replies

6. UNIX for Dummies Questions & Answers

[Solved] get value of free -m , used buffer

i would like to get the value -/+ buffers/cache used who is 212, how can i do this? i have free -m | grep -i mem | awk '{ print $2 }' for get value of total memory total used free shared buffers cached Mem: 7972 1237 6735 ... (2 Replies)
Discussion started by: prpkrk
2 Replies

7. Shell Programming and Scripting

expect_out buffer no such variable running script background

I am trying to use send and receive using expect. the expect_out(buffer) is working fine while it is running it as foreground. But the same script when it is ran as background, the expect_out(buffer) errored out. Is there any factor influence when we run script in foreground and in background? ... (0 Replies)
Discussion started by: shellscripter
0 Replies

8. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

9. Shell Programming and Scripting

expect_out(buffer) empty

I have only some info into my buffer, but after a rssi command I see the folowing lines expected into buffer but not present : rssi=-106 rssi=-109 I see in my buffer only the first part of the output, here you are a part of script : #!/usr/bin/expect -f #global expect_out match_max 10000000... (1 Reply)
Discussion started by: ugobale
1 Replies

10. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies
Login or Register to Ask a Question