I have the below script that will login to a Cisco router, then do a show ver and show run command outputing to a file.
My problem is often times the show run output can take a couple of minutes to complete, I could put in a sleep however there are over 1200 routers I run this against so I'd rather not drag it out for a long time.
Is there a way to watch for the output to finish and return to the command prompt or wait for "End" as Cisco configs always end with that.
Thanks for any help and yes I inherited this script
========================================================
#!/usr/bin/perl
# Include statements...
use Net::Telnet::Cisco;
# Global variables...
$mylog = "logfile";
$login = "user";
$pass = "passwordhere";
$enable = "enablepasshere";
# Pass the router name to remote variable...
if ($ARGV[0])
{
$remote=$ARGV[0];
}
# Run the sequence...
&connect();
crisco("terminal length 0");
crisco("show ver");
crisco("show run");
sleep(5);
&disconnect();
# Subroutines
# Writes to the logfile...
sub mylog
{
my $msg = shift;
$date=`date`;
chop($date);
open(LOG, ">>$mylog");
print LOG "$date : $msg\n";
close(LOG);
}
# Disconnects from the router...
sub disconnect
{
mylog("\nDisconnecting...\n");
$session->close();
}
# Exits to prompt & writes memory...
sub wr_mem
{
crisco("");
crisco("write memory");
}
# Simplifies sending commands to router via Net::Telnet::Cisco $session commands...
sub crisco
{
my $ioscmd = shift;
mylog("\ncrisco(): $ioscmd\n");
dir($session->errmsg) unless($session->cmd("$ioscmd"));
}
# Connects to the router & enters enable mode...
sub connect
{
print "Connecting to $remote...\n\n";
mylog("Connecting to $remote");
$session = Net::Telnet::Cisco->new(Host=>"$remote",Input_log=>"$remote.log",Errmode=>sub { my $errmsg = shift; },) or mylog("Connection to $remote FAILED!!");
$session->login("$login","$pass") or mylog("Login FAILED");
mylog("Enable Session FAILED") unless($session->enable("$enable"));
dir($session->errmsg) unless($session->enable("$enable"));
}
My problem is often times the show run output can take a couple of minutes to complete, I could put in a sleep however there are over 1200 routers I run this against so I'd rather not drag it out for a long time.
Is there a way to watch for the output to finish and return to the command prompt or wait for "End" as Cisco configs always end with that.
Thanks for any help and yes I inherited this script
========================================================
#!/usr/bin/perl
# Include statements...
use Net::Telnet::Cisco;
# Global variables...
$mylog = "logfile";
$login = "user";
$pass = "passwordhere";
$enable = "enablepasshere";
# Pass the router name to remote variable...
if ($ARGV[0])
{
$remote=$ARGV[0];
}
# Run the sequence...
&connect();
crisco("terminal length 0");
crisco("show ver");
crisco("show run");
sleep(5);
&disconnect();
# Subroutines
# Writes to the logfile...
sub mylog
{
my $msg = shift;
$date=`date`;
chop($date);
open(LOG, ">>$mylog");
print LOG "$date : $msg\n";
close(LOG);
}
# Disconnects from the router...
sub disconnect
{
mylog("\nDisconnecting...\n");
$session->close();
}
# Exits to prompt & writes memory...
sub wr_mem
{
crisco("");
crisco("write memory");
}
# Simplifies sending commands to router via Net::Telnet::Cisco $session commands...
sub crisco
{
my $ioscmd = shift;
mylog("\ncrisco(): $ioscmd\n");
dir($session->errmsg) unless($session->cmd("$ioscmd"));
}
# Connects to the router & enters enable mode...
sub connect
{
print "Connecting to $remote...\n\n";
mylog("Connecting to $remote");
$session = Net::Telnet::Cisco->new(Host=>"$remote",Input_log=>"$remote.log",Errmode=>sub { my $errmsg = shift; },) or mylog("Connection to $remote FAILED!!");
$session->login("$login","$pass") or mylog("Login FAILED");
mylog("Enable Session FAILED") unless($session->enable("$enable"));
dir($session->errmsg) unless($session->enable("$enable"));
}