From: Noah <ad...@en...> - 2008-06-10 23:56:05
|
Hi there, I am trying to capture the output of a fairly long configuration file but it aint working too well. Instead of seeing hundreds of lines I am finding only about 3-5 lines are captured. is there a better method? Note how the @showConfiguration variable is getting used. sub grab_config { open(OUTPUT, ">$output_filename") or die $!;; my $target = "${user}\@${ip}"; my $cmd = "ssh $target"; my $exp = new Expect() || die "Cannot spawn ssh command \n"; $exp->log_file($logfile); $exp->raw_pty(0); $exp->spawn("$cmd"); # # Might get the warning about "Are you sure you want to # continue connecting (yes/no)?" # $exp->expect(2, ['yes/no\)\? ', sub { my $fh = shift; $fh->send("yes\n");$stat=0;}]); $exp->expect($timeout, ['assword:', sub { my $fh = shift; $fh->send("$pw\n");$stat=0;}], [timeout => sub {print STDERR " *** login:Timed out waiting for (auth) 'assword:'\n"; $stat=1;}] ); $exp->send("$pw\n"); $prompt = "^$user\@[a-z\.0-9\-]+>"; $patidx = $exp->expect($timeout, [$prompt]); $exp->send("$blah\n"); $patidx = $exp->expect($timeout, [$prompt]); $exp->send("$blah\n"); my @showConfiguration = $exp->expect($timeout, [$prompt]); $exp->send("quit\n"); $exp->soft_close(); print OUTPUT @showConfiguration[3]; close (OUTPUT); } |