- priority: 5 --> 9
- status: open --> pending
Hi,
I have written a perl script to login in to cisco devices using Net::Telnet::Cisco modlue and do the configuration changes. The script reads the hostname and command to execute from a text file.
Script runs successfully when there is no error in getting telnet connection to a device but, it fails and exits when telnet connection to a device is not established and more importantly it does not read the next input from the text file and whole script exits.
Please help me in finding a way by which the script runs and goes to next entry of text file when it receives an error in telnet connection.
The script is below:
use strict;
use warnings;
use Net::Telnet::Cisco;
my $input_csv;
$input_csv = 'D:\input.txt';
open ( PTR1, "<$input_csv" ) or die "Cannot open input csv filename <<$input_csv>> in read mode : $!\n";
my $txt1;
while ( $txt1 = <PTR1> )
{
chomp $txt1;
print "working for entry [$txt1]\n\n";
my ( $host_name, $interface_name, $interface_desc, $enable_pwd );
( $host_name, $interface_name, $interface_desc, $enable_pwd ) = split ( /,/, $txt1);
my $session = Net::Telnet::Cisco->new(Host => "$host_name");
$session->login('vineet', 'vineet');
$session->enable("$enable_pwd");
$session->cmd('config t');
$session->cmd("interface $interface_name");
$session->cmd("description $interface_desc");
$session->cmd('end');
$session->cmd('write');
$session->close;
}
close ( PTR1 );
Regards
Vineet Singh