Hello,
I currently have a working perl script that connects to a CSV list of Cisco devices and excecutes commands. The problem I have is that some of the devices are SSHv1 and SSHv2 which are being skipped. I'm looking for a command example that will start an SSHv1 or SSHv2 session and execute commands if the Cisco device does not respond to telnet. Thank you in advance.
Here is an example of my working Telnet script:
<SNIP>
#!/usr/bin/perl
#
use Net::Telnet::Cisco;
use Term::ReadKey;
print "Router Reload v1.0\n
**Warning** This script will update the startup-config and schedule a reload for all devices listed in the reload file.\n
The reload will be scheduled for 8:00 GMT (3am EST, 2am CST, 1am MST, 12am PST).\n\n";
print "Enter username: ";
$user = <STDIN>;
chomp($user);
print "\n";
print "Enter password: ";
ReadMode('noecho');
$pass = ReadLine(0);
chomp($pass);
print "\n\n";
print "Enter filename. Example: reloads.year.month.day.csv
\n";
ReadMode('normal');
$State = <STDIN>;
chomp($State);
open (INDB, "./$State") or
die "cannot find file";
mkdir ("$State.logfiles");
mkdir ("$State.errors");
while (<INDB>)
{
$SiteData = $_;
chomp ($StoreData);
($SiteNumber, $loopback, $reload, $copytftpst, $tftpserver, $configpath, $deststcfg, $deletevlan) = split (/,/, $SiteData);
my $CISCO_IP = "$loopback";
my $username = "$user";
my $password = "$pass";
my $enable_password = "$pass";
my $error = 'errorout';
my $loginerror = 'loginout';
my $session = Net::Telnet::Cisco->new(Ho
st => $CISCO_IP, Input_log=> "$State.logfiles/$loopback
.txt", Timeout=> '120', Errmode=> 'return');
unless($session) {
#Do whatever error handling you want here
print "Could not connect to Store# $StoreNumber device: $CISCO_IP\n\n\n";
open ($error,">>./$State.errors
/$loopback
.txt");
print $error "Could not connect to Store# $SiteNumber device: $CISCO_IP\n";
close ($error);
next;
}
$session->login($username,
$password);
if($session->errmsg) {
open ($loginerror,">>./$State.e
rrors/$loo
pback.txt"
);
print $loginerror "Authentication failed";
close ($loginerror);
}
my @output = "";
my @host = "";
# Enable mode
if ($session->enable($enable_
password) )
{
@output = $session->cmd('show privilege');
@host = $session->cmd('sho run | include hostname');
print "@output for @host $loopback\n";
}
else
{
warn "Can't enable: " . $session->errmsg;
}
$session->cmd("$reload\n")
;
$session->cmd("$copytftpst
\n$tftpser
ver\n$conf
igpath\n$d
eststcfg")
;
$session->cmd("$deletevlan
\n\n");
print "$reload\n$deletevlan\n$co
pytftpst\n
$tftpserve
r\n$config
path\n$des
tstcfg\n\n
";
$session->close;
}
</SNIP>