#!/usr/bin/perl use Net::Appliance::Session; $switch_file = "/etc/scripts/switches.txt"; $user = "xxxxx"; $pass = "xxxxx"; $out_file = ">> /etc/scripts/portcount.txt"; if (-e "/etc/scripts/portcount.txt") { system("rm -f /etc/scripts/portcount.txt"); } open(OUT, $out_file); foreach $store_number (@ARGV) { chomp($store_number); open(STSWITCH, $switch_file); foreach $switch () { chomp($switch); next if $switch =~ /^#/; next if $switch !~ /\.st${store_number}\.meijer\.com/; $s = Net::Appliance::Session->new( Host => $switch, Transport => 'SSH'); $s->do_privileged_mode(0); eval { $s->connect( Name => $user, Password => $pass, SHKC => 0); $count = 0; @output = $s->cmd("show ip int brie"); $s->close(1); foreach $line (@output) { next if $line !~ /FastEthernet/; next if $line !~ /administratively down/; $count++; } $total += $count; #print $switch ." unused ports: ". $count ."\n"; }; if ($@) { print "Error while accessing the device: $switch\n"; print "The error was: $@\n\n"; } } print OUT "Total for store #". $store_number .": ". $total ."\n"; $total = 0; close(STSWITCH); } close(OUT);