Thread Expect nur das gewünschte anzeigen
(6 answers)
Opened by bigbrother at 2010-08-04 00:12
Damit man sehen kann wie es funktioniert:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #!/usr/bin/perl use strict; use warnings; use Expect; my @connection=qw(telnet localhost); my $user='xxxxx'; my $pass='*****'; my $timeout = 1; my $data=''; my $exp = Expect->new(); $exp->log_stdout(0); $exp->spawn(@command) or die "Cannot spawn @connection: $!\n"; $exp->expect($timeout, [ qr/login:/i, sub{ my $exp = shift; $exp->send("$user\n"); exp_continue; }], [ qr/password:/i, sub{ my $exp = shift; $exp->send("$pass\n"); exp_continue; }], '-re', qr/[#>:\$] $/, ); $exp->log_stdout(1); $exp->print(qq{cat /etc/fstab\n}); $exp->expect($timeout,'-re',qr/.+[#>:\$] $/s); $data=$exp->match(); $exp->print("exit\n"); $exp->soft_close(); print "OUTPUT:"; print $data; |