How to get the full output from the expected when the size of the internal buffer in the size of expect_out (buffer) exceeds?

I don’t know what is going on, but I don’t get the full output from the remote command executed, perhaps because it expects the internal buffer to be executed.

proc SendCommands { Commands } { global prompt log errlog foreach element [split $Commands ";"] { expect { -re $prompt {send -- "$element\r"} } set outcome "$expect_out(buffer)" foreach line [split $outcome \n] { foreach word [regexp -all -inline {\S+} $line] { if {( [string index [string trimleft $line " "] 0 ] == "%")} { puts "$outcome" exit 1 } } } puts "$outcome" } } set timeout 30 foreach host [ split $hosts "\;" ] { spawn ssh -o "StrictHostKeyChecking no" " $username@ $host" match_max 10000000 expect { timeout { send_user "\nFailed to get password prompt\n"; exit 1 } eof { send_user "\nSSH failure for $host\n"; exit 1 } "*?assword:*" { send -- "$password\r" } } expect { timeout { send_user "\nLogin incorrect\n"; exit 1 } eof { send_user "\nSSH failure for $host\n"; exit 1 } -re "$prompt" { send -- "\r" } } set timeout 300 SendCommands "$Commands" } 

this is how i execute it:

 ./sendcommand aehj SWEs-elmPCI-B-01.tellus comnet1 "terminal length 0;show int description" "(.*#)$" 

I get full output only when I delete log user 0 , but when I use the puts command in the fucnction send commands above, I get about 90 percent of them with 10% of the final data at the end is not displayed.

In one case, I think it is necessary to use the negation of the regular expression in expectation, but it does not seem to work.

  expect { -re ! $prompt {puts $expect_outcome(buffer)} } 

EDIT: I get all the output once when it runs about 5 or 7 times

+6
source share
1 answer

After a bit of searching, I came up with this and it seems to work, but let me know about any cases or better answers:

I set match_max = 1000, then

  expect { -re $prompt {send -- "$element\r"} full_buffer { append outcome $expect_out(buffer) exp_continue } } append outcome $expect_out(buffer) puts $outcome 

but still, when I set match_max = 10000 or 100, it will work again

+1
source

Source: https://habr.com/ru/post/943947/


All Articles