From: Noah <ad...@en...> - 2007-11-14 23:59:19
|
Matt, I am not doing something correct here. I run my script and get the following: "Can't call method "put" on an undefined value at ./maintenance.check.pl line 96." Cheers, Noah Matt Zagrabelny wrote: > On Wed, 2007-11-14 at 15:39 -0600, Noah wrote: > > [...] > >> is there a way to capture the output with perl-expect into an array? > > Here are some snippets of what I have done in the past, though I do > things a little differently now, you will get the idea... hopefully. ;) > > Subroutine to send a command to Cisco devices and capture the output in > the scalar reference $receive_buffer. > > sub send_and_receive { > my $configs = shift; > my $send_string = shift; > my $receive_buffer = shift; > my $command = shift; > my $wait_for_found = (@_) ? shift : undef; > my $more_output = (@_) ? shift : '--More--'; > my $continue_command = (@_) ? shift : " "; > my $wait_for = (@_) ? shift : '>$'; > > # send whatever it is we are to send > $command->put($send_string); > > # now wait for the "wait_for" meanwhile saving > # all the output into receive_buffer > my $done = undef; > until ($done) { > my ($prematch, $match) = (undef, undef); > ($prematch, $match) = > $command->waitfor(Match => '/'.$more_output.'/i', > Match => '/'.$wait_for.'/i', > Match => '/\\[X\\] Exit.*:/ism', > Timeout => $configs->{management_timeout}); > > if ($receive_buffer ne undef) { > $$receive_buffer .= $prematch.$match; > } > > if ($match =~ /$more_output/i) { > $command->put($continue_command); > } elsif ($match =~ /$wait_for/) { > $$wait_for_found = 1 if ($wait_for_found); > $done = 1; > } elsif ($match =~ /\[X\] Exit.*:/ism) { > $$wait_for_found = 1 if ($wait_for_found); > $done = 1; > } > } > } > > $text_io = ''; > &send_and_receive($configs, > "show interface status\n", > \$text_io, > $connection, > \$found_prompt); > > my @lines = split /\n/, $text_io; > for (@lines) { > $_ = &trim($_); > } > > sub trim { > my $s = shift; > $s =~ s/^\s*//; > $s =~ s/\s*$//; > return $s; > } > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |