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
source share