Imagotype-NetworkDataPedia (1)

NetworkDataPedia © 2018-2020  |  Editorial Team   |   Privacy Policies  |  Contact Us          Website built by DYCMarketing 

Perls of Wisdom

May 28, 2012

In this video I show some of the basics for creating a simple perl script to collect output from a cisco switch and write it to a log


here's an example of using the script

perl password


the perl script is below.  simply copy and past into a text editor and save with a .pl extension like

use Net::Telnet::Cisco;
use Time::localtime;

$host = $ARGV[0]; #this is the first value entered after
$password = $ARGV[1]; #this is the second value entered after

print " script running .... \n";

$session = Net::Telnet::Cisco->new(Host => $host);#open Telnet session
$session->login('login', $password); # 'login' is requierd since I do not have a username configured
print ".Logged in\n";

$session->cmd('term len 0'); #term len 0 gets rid of the more prompt
my @sh_log = $session->cmd('show log'); # Execute the show log command
print "..Got Log\n";

$date_time = sprintf("%02d-%02d-%02d_%02d_%02d_%02d",  localtime->mon()+1,   localtime->mday(), (localtime->year() + 1900),localtime->hour() , localtime->min() , localtime->sec() ) ;
$file= ">>".$date_time . ".log"; #create filename for log file

open LOG, $file || die "cannot open output file";
print LOG "Log Created $file\n";
print LOG "@sh_log";
close (LOG);
print ".File $file created.\n";





Share on Facebook
Share on Twitter
Please reload

Sponsored By:


Recent Posts

November 12, 2019

Please reload