The answer to your speculation " For some reason i get the below error" is most likely in the "input.log" file that tracks the session.

One big problem with your code is that it does no error checking.

You should check for errors when you "open DEVICE", and check for a valid $session when it is opened.

Most importantly, you should check for a non-zero return value from $session->login, and bail, if that fails.

open (my $DEVICE, "<", 'device.list') or die "Could not open device li +st:$!"; while (<$DEVICE>) { chomp; my $routerIP = $_; print "Router IP is $routerIP,"; my $session = Net::Telnet::Cisco->new(Host => "$routerIP", Input_log +=>"input.log", ); if (! $session){ warn "Could not open session to $routerIP\n"; next; } if (! $session->login("$username", "$password") ){ warn "Could not login to $routerIP\n"; next; } my @output = $session->cmd("$cmd"); .... process ... }

        Profanity is the one language all programmers know best.


In reply to Re: Problems with Cisco Router Perl Query by NetWallah
in thread Problems with Cisco Router Perl Query by Tanto4545

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.