I am having
difficulty discovering why a part of my script is doing what it is doing. I have
a script that polls switches every 5 minutes to discover new MAC's. Everything
works fine for discovering new MAC's but now I want to test for existing MAC's
that have moved.
The common factor of
both files being the MAC Address.
My Master file is as
follows which is pushed into @echeck and there are 1329 lines:
MAC,Netbios,Building-floor,Switchblade,Port
ie..
0:8:74:47:57:af,bob,380-3,Blade4,17
@rich is:
IP-MAC-Port
1.2.3.4-0:8:74:47:57:af-20
Here is a snippet of
the code that is giving me problems, it seems my loop is not exiting or it is
reiterating over it several times. Should I be using
hashses?
...
my
$scratch='/home/snmp/zexist';
my $scratch2='/home/snmp/zchange';
my $scratch3='/home/snmp/znew';
open (SCRATCH, ">>$scratch");
open (SCRATCH2,">>$scratch2");
open (SCRATCH3,">>$scratch3");
foreach my $line(@rich){
my($fh,$fm,$fp)=split(/-/, $line);
foreach my $lne(@echeck){
my($checkm,$checkcn,$checkl,$checkb,$checkp)=split(/,/, $lne);
if ($fm eq $checkm && ($fp == $checkp)){
print SCRATCH "$checkm,$checkp";
}elsif ($fm eq $checkm && ($fp != $checkp)){
print SCRATCH2 "$checkm,$checkp";
print SCRATCH2 "$fm,$fp\n";
}elsif ($fm ne $checkm){
print SCRATCH3 "$fm,$fp\n";
}
}}
....
my $scratch2='/home/snmp/zchange';
my $scratch3='/home/snmp/znew';
open (SCRATCH, ">>$scratch");
open (SCRATCH2,">>$scratch2");
open (SCRATCH3,">>$scratch3");
foreach my $line(@rich){
my($fh,$fm,$fp)=split(/-/, $line);
foreach my $lne(@echeck){
my($checkm,$checkcn,$checkl,$checkb,$checkp)=split(/,/, $lne);
if ($fm eq $checkm && ($fp == $checkp)){
print SCRATCH "$checkm,$checkp";
}elsif ($fm eq $checkm && ($fp != $checkp)){
print SCRATCH2 "$checkm,$checkp";
print SCRATCH2 "$fm,$fp\n";
}elsif ($fm ne $checkm){
print SCRATCH3 "$fm,$fp\n";
}
}}
....
(scratch) zexist
looks like this: (problem being all 24 ports are in use and 2 have changed so
there should be 22 and 4th one is one that has changed)
0:1:e6:71:4e:2a,14
0:6:5b:ec:fd:c4,1
0:a:e4:1:c6:b,9
0:c:f1:a6:5a:e0,6
0:e0:7b:2:c1:40,23
0:6:5b:ec:fd:c4,1
0:a:e4:1:c6:b,9
0:c:f1:a6:5a:e0,6
0:e0:7b:2:c1:40,23
(scratch2) zchange
looks like this: ( this looks like it worked, the two ports that have
changed)
0:8:74:47:57:af,17
0:8:74:47:57:af,20
0:c:f1:a6:5a:e0,39
0:c:f1:a6:5a:e0,6
0:8:74:47:57:af,20
0:c:f1:a6:5a:e0,39
0:c:f1:a6:5a:e0,6
(scratch3) znew
looks like this: (problem, takes zexists and repeats each one 1329
times)
0:1:e6:71:4e:2a,14
0:1:e6:71:4e:2a,14
0:1:e6:71:4e:2a,14
etc...
etc...
Thanks,
Rich
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>