in reply to Cisco Telnet

Hi,

after doing all advice theoretically (I'm not a network admin), I coded a small test to see where the problem is:

1 #!/usr/bin/env perl 2 use 5.010; 3 use strict; 4 use utf8; 5 use warnings qw(all); 6 7 use local::lib 'cisco'; 8 9 use Net::Telnet::Cisco; 10 11 my $session = Net::Telnet::Cisco->new( 12 Host => "192.168.168.2", 13 Timeout => 3, 14 ); 15 $session->login(Password => 'secret');

A run of that shows:

problem connecting to "192.168.168.2", port 23: connect timed-out at a +m304.pl line 11

AAAAHHH, the exception is thrown on line 11. It seems that the method new is doing a connect to host mentioned. IMHO that's an API misdesign, but anyways.

Conclusion:

BUT: Now the interesting part. Putting an eval around the method new can catch the exception, but not the exception message. And that's worth another thread herein.

Best regards
McA

Replies are listed 'Best First'.
Re^2: Cisco Telnet
by mvip (Acolyte) on Aug 26, 2013 at 14:20 UTC

    Hi, tnx McA i get it now ... i have put the eval in wrong place. Here is what iv done

    eval { my $session = Net::Telnet::Cisco->new(Host => "$device", Input_log => "perllogrouter/router$i.log", ); $session->login(Password => $curpwd); if ($session->enable("$curpwd")) { # Execute a command @output = $session->cmd ('show running-config | section hostname') +; print "@output\n"; print " ======================================================\n"; } $session->close; }; if ($@) {print "Error: $@\n"}

    before i was put the eval in "$seesion->login(password=>$curpwd);" , now its works fine ... tnx again for the help and support.

Re^2: Cisco Telnet
by mvip (Acolyte) on Aug 26, 2013 at 14:25 UTC

    i would like if its possible to write in the log file the error form eval in this code. From "perllogrouter/router$i.log"the eval error to be put there if its possible.

    eval { my $session = Net::Telnet::Cisco->new(Host => "$device", Input_log => "perllogrouter/router$i.log", ); $session->login(Password => $curpwd); if ($session->enable("$curpwd")) { # Execute a command @output = $session->cmd ('show running-config | section hostname') +; print "@output\n"; print " ======================================================\n"; } $session->close; }; if ($@) {print "Error: $@\n"}

      sorry for the noob questions but i done this. So here it is for shearing

      if ($@) { my $logtext = 'ruterproba.txt'; open my $fh, '>>',$logtext or die "Nemoze da zapise vo $logtext poradi:$! "; print $fh "Error: $@\n"}

      I dont know why i start learning perl, but i have to admit i have finish great jobs with him :)) i love it and im continuing to learn more and more :) and tnx for support .....