#!/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++; } } } #### [scripts]# perl cisco_crs_int_check.pl total 24 drwxr-xr-x. 2 root root 16384 Jan 30 10:50 . drwxr-xr-x. 4 root root 4096 Jan 29 10:12 .. -rw-r--r--. 1 root root 92 Jan 30 10:50 log.router1.Bundle-Ether11.txt -rw-r--r--. 1 root root 0 Jan 30 10:50 log.router1.Bundle-Ether12.txt 0 0 Attempting to connect to routers... Polling router1 Bundle-Ether11 ......... please wait Thu Jan 30 15:51:37.001 UTC MTU 9192 bytes, BW 240000000 Kbit (Max: 240000000 Kbit) Reported Speed: 240000000 ...... Polling router1 Bundle-Ether12 ......... please wait mux_client_request_session: read from master failed: Broken pipe ssh_exchange_identification: read: Connection reset by peer Reported Speed: 0 ...... The End....