From: Rui M. <rme...@te...> - 2007-05-08 13:45:09
|
Hi. I'm having a problem using Expect.pm I created a script to do automated ssh to several hosts. One thing I need to do is to enter several Cisco routers, execute the commands terminal length 0 and show running-config and save some of the output to a file. It's all working fine, and as the commands are executed the correct output is automatically printed in the screen (expect.pm default option). However, when the output of the command is very long (show running-config) the output is not correctly stored in my variable $stdout, it's always truncated in the same spot! Example: (These are parts of my code) #--------------------------------------------------------------------------- ------------------------ my $exp; my $prompt_default = "[\\\$%#>]\\s*(\\(enable\\)|)\\s*"; # A strange prompt, but it's working fine $exp = Expect->spawn("ssh ${username}\@${host}") or die "ERROR: Couldn't spawn ssh connection, $!\n"; $exp->log_file($opts{'l'}); $exp->restart_timeout_upon_receive(1); $exp->max_accum(0); # Executing Login - all is made correctly # (.) # Executing commands # (.) # Retrieving Output $exp->clear_accum(); $exp->expect($timeout, [ qr/$prompt_default/, sub { my $fh = shift; $stdout = $exp->before() . $exp->match() . $exp->after(); print $fh "\n"; #exp_continue; # Don't continue } ] ) or do{ erro("Invalid Prompt, " . $exp->exp_error() . "\n"); $exp->soft_close(); return; }; print "###############\n"; print "$stdout\n"; print "###############\n"; #--------------------------------------------------------------------------- ------------------------ What happens is that when I print $stdout the output I get is: ############### (1st part of output) ############### (2nd part of output) And if I save $stdout to a file, only 1st part is saved (2nd part gets truncated). Does anyone know why this is happening? I tried putting some sleeps but that didn't solve my problem. It almost seems that this works as some kind of buffer, that only when emptied can store more data! However, the qr/$prompt_default/ is working fine, as well as the automatic prints to the screen! Thanks in advance. |