|< 1 2 3 >| | 23 Einträge, 3 Seiten |
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
my $session = Net::Telnet::Cisco-> new (Host => '10.100.2.200');
$session->login('admin', 'cisco');
# Execute a command
my @output = $session->cmd('show run');
my $string = join '',@output;
my @infos = split /interface ATM/,$string;
#shift @infos;
my %hash;
for my $interface(@infos){
my ($bez) = $interface =~ /^([^\n]+)/;
my @daten = $interface =~ /(daten .*?cbr 128)/sg;
for my $daten(@daten ){
my ($id,$ip) = $daten=~ /(\s*[\d\/]+).*?protocol ip ((?:\d{1,3}\.){3}\d{1,3})/s;
push @{$hash{'ATM'.$bez}}, [$id,$ip];
}
}
for my $atm(keys %hash){
print sprintf("%10s | %10s | %15s\n",$atm,'Daten','IP');
print sprintf("%10s | %10s | %15s\n",' ',@$_) for @{$hash{$atm}};
}
| DATEN | IP
| 22/180 | 10.200.50.81
| 22/190 | 10.200.50.83
1
2
3
4
5
6
7
Daten1 | Daten2 | IP
22 | 180 | 10.200.50.81
122 | 202 | 10.200.51.82
Dass ich die Spalte " Daten "wiederrum Teilen
kann mich jemand helfen wie ich in der Code machen damit ich von "22/180 " auf "22" und "180" komme.
1
2
3
4
5
6
7
for my $atm(keys %hash){
print sprintf("%10s | %10s | %10s | %15s\n",$atm,'Daten1','Daten2','IP');
for my $elem(@{$hash{$atm}}){
my @array = ($elem->[0],split(/\//,$elem->[1]),$elem->[2]);
print sprintf("%10s | %10s | %15s\n",' ',@array);
}
}
1
2
3
4
5
6
7
8
9
| Daten1| Daten2| IP
| 22/180 | 10.200.50.81
| 22/190 | 10.200.50.83
| 22/202 | 10.200.50.82
| 122/202 | 10.200.51.82
Vielleicht muss ich an der oberen teil des codes was ändern?
print sprintf("%10s | %10s | %10s | %15s\n",' ',@array);
1
2
3
4
5
6
7
8
9
| Daten1 | Daten2 | IP
Use of uninitialized value in sprintf at ./hash.pl line 33.
| 22/180 | 10.200.50.81|
Use of uninitialized value in sprintf at ./hash.pl line 33.
| 22/190 | 10.200.50.83|
Use of uninitialized value in sprintf at ./hash.pl line 33.
| 22/202 | 10.200.50.82|
Use of uninitialized value in sprintf at ./hash.pl line 33.
| 122/202 | 10.200.51.82|
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
#!/usr/bin/perl -w
#DatenbankAbfragen
use strict;
use warnings;
use DBI;
use Net::Telnet::Cisco;
my $session = Net::Telnet::Cisco-> new (Host => '10.100.20.100);
$session->login('admin', 'name);
# Execute a command
my @output = $session->cmd('show run');
my $string = join '',@output;
my @infos = split /interface ATM/,$string;
#shift @infos;
my %hash;
for my $interface(@infos){
my ($bez) = $interface =~ /^([^\n]+)/;
my @data = $interface =~ /(pvc.*?cbr 128)/sg;
for my $daten(@data){
my ($id,$ip) = $pvc =~ /(\s*[\d\/]+).*?protocol ip ((?:\d{1,3}\.){3}\d{1,3})/s;
push @{$hash{'ATM'.$bez}}, [$id,$ip];
}
}
for my $atm(keys %hash){
print sprintf("%10s | %10s | %15s\n",$atm,'Daten','IP');
print sprintf("%10s | %10s | %15s\n",' ',@$_) for @{$hash{$atm}};
}
|< 1 2 3 >| | 23 Einträge, 3 Seiten |