#!/usr/bin/perl -w use Net::Ping; use Net::OpenSSH; $username = "user"; $password = "password"; @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"; $cmd = ""; foreach $intname (@interface) { $cmd = "$cmd\nshow interfaces $intname | include Bundle\nshow interfaces $intname | include BW\n"; } } 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; print "\n\nPolling $hostname ......... please wait\n"; open (LOGONE, ">/root/scripts/logs/interfaces/log.$hostname.txt"); $out = $ssh -> capture ("$cmd"); print "$out\n"; print LOGONE $out; close (LOGONE); open (LOGTWO, "/root/scripts/logs/interfaces/log.$hostname.txt"); $interfacecount = 0; @interfacenamerecord = (); @interfacespeedrecord = (); while ( ) { @splitset = split (/\s+/, $_); $speedcount = 0; foreach $splittest (@splitset) { if ($splittest =~ /Bundle/) { $interfacenamerecord[$interfacecount] = $splitset[0]; } if ($splittest =~ /BW/) { $locationcount = $speedcount+1; $interfacespeedrecord[$interfacecount] = $splitset[$locationcount]; $interfacecount++; } $speedcount++; } } $printcount = 0; $intholder = ""; foreach $intholder (@interfacenamerecord) { print "Interface $interfacenamerecord[$printcount] reported speed is $interfacespeedrecord[$printcount]\n"; $printcount++; } close (LOGTWO); $testcount++; } } #### [scripts]# perl cisco_crs_int_check.pl total 24 drwxr-xr-x. 2 root root 16384 Jan 30 14:20 . drwxr-xr-x. 4 root root 4096 Jan 29 10:12 .. -rw-r--r--. 1 root root 326 Jan 30 14:20 log.router1.txt 0 0 Attempting to connect to routers... Polling router1 ......... please wait Thu Jan 30 19:26:37.629 UTC Bundle-Ether11 is up, line protocol is up Thu Jan 30 19:26:37.975 UTC MTU 9192 bytes, BW 240000000 Kbit (Max: 240000000 Kbit) Thu Jan 30 19:26:38.268 UTC Bundle-Ether12 is up, line protocol is up Thu Jan 30 19:26:38.545 UTC MTU 9192 bytes, BW 340000000 Kbit (Max: 340000000 Kbit) Interface Bundle-Ether11 reported speed is 240000000 Interface Bundle-Ether12 reported speed is 340000000 The End....