#!/usr/bin/perl -w use Net::Ping; use Net::OpenSSH; $username = "user"; $password = "pass"; @interface = (); #Input data to fill above variables get_router_data(); $listfiles = system("ls -al /root/scripts/logs/interfaces/"); $deletefiles = system("rm -rf /root/scripts/logs/interfaces/*"); print "$listfiles\n$deletefiles\n\n"; print "\nAttempting to connect to routers...\n"; $pingtest = Net::Ping->new("icmp"); cisco_test(); print "\n\nThe End....\n\n"; sub get_router_data { $hostname = "router1"; $interface[0] = "Bundle-Ether11"; $interface[1] = "Bundle-Ether12"; $routercount = 2; } sub cisco_test { if ($pingtest->ping($hostname, 2)) { $ssh = Net::OpenSSH->new("$hostname", user => $username, password => $password, master_stderr_discard => 1) || warn("\$!\n"); $testcount = 0; while ($testcount < $routercount) { $reportedspeed = 0; print "\n\nPolling $hostname $interface[$testcount] ......... please wait\n"; open (LOGONE, ">/root/scripts/logs/interfaces/log.$hostname.$interface[$testcount].txt"); $out = $ssh -> capture ("show interfaces $interface[$testcount] | include BW"); print "$out\n"; print LOGONE $out; close (LOGONE); open (LOGTWO, "/root/scripts/logs/interfaces/log.$hostname.$interface[$testcount].txt"); while ( ) { @splitset = split (/\s+/, $_); $speedcount = 0; foreach $splittest (@splitset) { if ($splittest =~ /BW/) { $locationcount = $speedcount+1; $reportedspeed = $splitset[$locationcount]; } $speedcount++; } } print "Reported Speed: $reportedspeed ...... \n"; close (LOGTWO); $testcount++; } } }