uninitialized value $XX in substitution iterator
Bonjour,
pour un besoin en réseaux, je dois récupérer le contenus d'une access-list (TOTO) d'un routeur et doit rajouter ce contenue à une autre existante (10).
Le premier script fonctionne ...de manière aléatoire.
DONNEES
Citation:
# Ceci est un commentaire
!
ip access-list extended ACL_FAILLES_RESIDUELLES
ip access-list extended ACL_FAILLE_DROP
ip access-list extended DATA1
ip access-list extended DATA2
ip access-list extended DATA3
ip access-list extended DATA4
ip access-list extended TACACS_NTP
ip access-list extended VIDEO
ip access-list extended VOIX
access-list 1 permit 12.136.2.132
access-list 1 permit 69.136.2.4
access-list TOTO permit 45.98.195.29
access-list TOTO permit 10.117.6.19
access-list TOTO permit 10.200.80.28
access-list TOTO permit 130.98.220.169
access-list TOTO remark ssh pour TITI
access-list TOTO permit 10.11.12.174
access-list TOTO permit 79.136.2.0 0.0.0.255
access-list TOTO permit 52.118.206.0 0.0.0.255
access-list 10 permit 109.0.80.2
access-list 10 permit 32.136.2.0 0.0.0.255
access-list 10 permit 130.64.0.0 0.63.255.255
access-list 10 permit 77.118.206.0 0.0.0.255
access-list 10 permit 62.39.9.0 0.0.0.255
access-list 10 permit 46.59.0.0 0.0.31.255
access-list 10 permit 198.30.97.108 0.0.0.3
access-list 10 permit 86.79.0.0 0.0.255.255
!
line vty 0 4
access-class in 10 vrf-also
exec-timeout 5 0
rotary 1
transport input telnet
line vty 5 10
access-class in TOTO
exec-timeout 5 0
rotary 1
transport input ssh
!
Code:
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
| die "Maximum 1 arguement" if (@ARGV >= 2);
open (my $fh, "<", "$ARGV[0]") or die "Cannot open $!";
my %hash_vty;
my $vty;
my $acl_num;
my %acl_standard; # hash_vty contenant toutes les ACL par numéro ou nom
my $numero_acl;
while (my $ligne = <$fh>) {
chomp($ligne);
next if ($ligne =~ /^[!#]/);
if ($ligne =~ /^access-list/) {
my @split = (split /\s/, $ligne);
push @{$acl_standard{"$split[1]"}}, $ligne;
}
if ($ligne =~ /^line vty/) {
$vty = $ligne;
} else {
if ($ligne =~ /\saccess-class/) {
$acl_num = $ligne;
#crée la clé uniquement si une valeur lui est associée => ici la valeur est la présence ou pas d'access-group
$hash_vty{$vty} = $acl_num;
}
}
}
close $fh;
foreach my $key (keys %hash_vty) {
if ($key =~ /\b0\b/) {
my @split = (split /\s/, $hash_vty{$key});
$numero_acl = $split[-1]; # récupère le numéro ACL sur VTY 0
print "$numero_acl\n";
} elsif ($key !~ /\b0\b/) {
my @split = (split /\s/, $hash_vty{$key});
foreach (@{$acl_standard{"$split[-1]"}}) { # récupére le numero ou nom acl client
s/$split[-1]/$numero_acl/; # Remplace le numero acl client par numero acl sfr
push @{$acl_standard{"$numero_acl"}}, $_; # Rajout de l'ACL client avec le numéro modifié dans ACL SFR
}
}
}
print "$_\n" foreach @{$acl_standard{"$numero_acl"}}; |
RESULTAT NON DESIRE ALEATOIREMENT
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
Use of uninitialized value $numero_acl in substitution iterator at test.pl line 83.
Use of uninitialized value $numero_acl in string at test.pl line 84.
access-list 10 permit 109.0.80.2
access-list 10 permit 32.136.2.0 0.0.0.255
access-list 10 permit 130.64.0.0 0.63.255.255
access-list 10 permit 77.118.206.0 0.0.0.255
access-list 10 permit 62.39.9.0 0.0.0.255
access-list 10 permit 46.59.0.0 0.0.31.255
access-list 10 permit 198.30.97.108 0.0.0.3
access-list 10 permit 86.79.0.0 0.0.255.255
Si je remplace le bloc suivant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| foreach my $key (keys %hash_vty) {
if ($key =~ /\b0\b/) {
my @split = (split /\s/, $hash_vty{$key});
$numero_acl = $split[-1]; # récupère le numéro ACL sur VTY 0
print "$numero_acl\n";
} elsif ($key !~ /\b0\b/) {
my @split = (split /\s/, $hash_vty{$key});
foreach (@{$acl_standard{"$split[-1]"}}) { # récupére le numero ou nom acl client
s/$split[-1]/$numero_acl/; # Remplace le numero acl client par numero acl sfr
push @{$acl_standard{"$numero_acl"}}, $_; # Rajout de l'ACL client avec le numéro modifié dans ACL SFR
}
}
} |
par 2 bloc, ca fonctionne à chaque fois
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| foreach my $key (keys %hash_vty) {
if ($key =~ /\b0\b/) {
my @split = (split /\s/, $hash_vty{$key});
$numero_acl = $split[3]; # récupère le numéro ACL sur VTY 0
print "$numero_acl\n";
}
}
foreach my $key (keys %hash_vty) {
if ($key !~ /\b0\b/) {
my @split = (split /\s/, $hash_vty{$key});
foreach (@{$acl_standard{"$split[3]"}}) { # récupére le numero ou nom acl client
s/$split[-1]/$numero_acl/; # Remplace le numero acl client par numero acl sfr
push @{$acl_standard{"$numero_acl"}}, $_; # Rajout de l'ACL client avec le numéro modifié dans ACL SFR
}
}
} |
RESULTAT
Citation:
access-list 10 permit 109.0.80.2
access-list 10 permit 32.136.2.0 0.0.0.255
access-list 10 permit 130.64.0.0 0.63.255.255
access-list 10 permit 77.118.206.0 0.0.0.255
access-list 10 permit 62.39.9.0 0.0.0.255
access-list 10 permit 46.59.0.0 0.0.31.255
access-list 10 permit 198.30.97.108 0.0.0.3
access-list 10 permit 86.79.0.0 0.0.255.255
access-list 10 permit 45.98.195.29
access-list 10 permit 10.117.6.19
access-list 10 permit 10.200.80.28
access-list 10 permit 130.98.220.169
access-list 10 remark ssh pour TITI
access-list 10 permit 10.11.12.174
access-list 10 permit 79.136.2.0 0.0.0.255
access-list 10 permit 52.118.206.0 0.0.0.255
Merci de votre aide.