|< 1 2 >| | 16 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
open (NAVI ,"$Ausgabe ");
while (my $line = <NAVI>) {
if ($line =~ m/SPPORT/ ) {
$port_section = 1;
}
if($port_section == 1) {
next if($line =~ m/^SP\sName:\s+SP+\s+($SP)/);
next if($line =~ m/^SP\sPort\sID:\s+($PORT)/);
if($line =~ m/^Link\sStatus:\s+(\w+)/){
$status_link = $1; print"$status_link\n";
}
}
close (NAVICLIOUT);
1
2
next if($line =~ m/^SP\sName:\s+SP+\s+($SP)/);
next if($line =~ m/^SP\sPort\sID:\s+($PORT)/);
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/perl use strict; use warnings; my ( $sp, $port ) = qw( A 5 ); # perldoc perlretut; perldoc perlrequick; perldoc perlre my $regex = qr{ SP\sName:\sSP\s\Q$sp\E \s+ SP\sPort\sID:\s\Q$port\E \s+ .* Link\sStatus:\s(\S+) \s+ }sx; { # perldoc perlvar local $/ = "\n\n"; while ( my $block = <DATA> ) { if ( $block =~ $regex ) { print "Link Status: $1\n"; } } } __DATA__ SP Name: SP A SP Port ID: 4 SP UID: 50:06:01:60:C1:E0:2B:7A:50:06:01:60:41:E0:2B:7A Link Status: Up Port Status: Online Switch Present: YES Switch UID: 10:00:00:05:1E:03:D9:16:20:07:00:05:1E:03:D9:16 SP Source ID: 67328 MAC Address: Not Applicable SFP State: Online Reads: 3064353 Writes: 17936913 Blocks Read: 103971645 Blocks Written: 867380028 Queue Full/Busy: 0 SP Name: SP A SP Port ID: 5 SP UID: 50:06:01:60:C1:E0:2B:7A:50:06:01:61:41:E0:2B:7A Link Status: Down Port Status: Online Switch Present: NO MAC Address: Not Applicable SFP State: Online Reads: 0 Writes: 74801 Blocks Read: 0 Blocks Written: 19186170 Queue Full/Busy: 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use strict; use warnings; use Getopt::Long; GetOptions( 'sp=s' => \my $sp, 'p=n' => \my $port, ); my $file = 'file.txt'; open my $fh, '<', $file or die $!; { local $/ = "\n\n"; while(my $block = <$fh> ){ next unless index( $block, 'SP Name: SP ' . $sp ) != -1 and index( $block, 'SP Port ID: ' . $port ) != -1; my ($status) = $block =~ /Link Status: (\w+)/; print "Link status for SP $sp (Port $port): $status\n"; } } close $fh;
Gast+2008-11-18 14:25:16--leider bekomme ich keine Ausgabe.
ich habe $SP = $ARGV[] und $PORT = $ARGV[] definiert.
hat das eine Auswirkung?
|< 1 2 >| | 16 Einträge, 2 Seiten |