remove interface
[dell-switch] / neighbours.pl
index 8e42b9c..e9d960b 100755 (executable)
@@ -2,12 +2,18 @@
 use warnings;
 use strict;
 use autodie;
+use Data::Dump qw(dump);
 
-# ./sw-name-mac.sh
-# ./sw-names | xargs -i ./dell-switch.pl {} 'show lldp neighbors'
-# /home/dpavlin/mikrotik-switch/m-neighbour
+if ( $ARGV[0] eq 'update' ) {
+       print <<__SH__
+./sw-name-mac.sh
+./sw-names | xargs -i ./dell-switch.pl {} 'show lldp neighbors'
+/home/dpavlin/mikrotik-switch/m-neighbour
+__SH__
+       ;
+       exit 0;
+};
 
-use Data::Dump qw(dump);
 
 my $debug = $ENV{DEBUG} || 0;
 
@@ -30,6 +36,7 @@ while(<$f>) {
 
 sub mac2name {
        my ( $mac, $name ) = @_;
+       return unless defined $mac;
 
        $mac = lc($mac);
 
@@ -159,8 +166,14 @@ foreach my $file ( glob('log/*lldp*') ) {
 
 # prase MikroTik /ip neighbor print detail terse
 
-foreach my $file ( glob('../mikrotik-switch/out/*neighbor*'), glob('../tilera/out/*neighbor*') ) {
-       my $name = $1 if $file =~ m{out/([\w\-]+)\.ip neighbor};
+my $patt = 'ip neighbor print detail terse';
+$patt =~ s{\s}{\\ }g; # escape spaces
+my @files = ( map { $_ . '/*' . $patt } qw( ../mikrotik-switch/out/ ../tilera/out/ ));
+@files = map { glob $_ } @files;
+warn "XXX $patt files=",dump(\@files) if $debug;
+
+foreach my $file ( @files ) {
+       my $name = $1 if $file =~ m{out/+([\w\-]+)\.ip neighbor};
        print "## [$name] file $file\n" if $debug;
        open(my $f, '<', $file);
        while(<$f>) {