Hi All

I have written a small script that would ideally login into a cisco router and run a command and display the output onto console but i have encountered with an error and not able to proceed further.

Initially i encountered with error as pattern match timed out.

Found an perl monk link where it was mentioned to add line "$session->print("\r"); # required to wakeup.".

After adding the above line i'm getting error as below even though username and password are correct

Error: login failed: access denied or bad username at core_switch.pl line 29

I'm suspecting its something related to prompt and delay in passing username and password, but not sure how to overcome that

Please post a sample code and point me in the right direction to avoid the error and connect Cisco device

Is there a way where whenever i execute this script, it should prompt me to input the username and password for switch

I would like to know both ways i.e. hard coding of username and password, and also when i execute the script it should prompt for username and password

My code

#!/usr/bin/perl use strict; use Net::Telnet; use Net::Telnet::Cisco; # Command line argument while executing the script if ($#ARGV < 0) { print "Please run the script with correct arguments\n\n"; print "Usage Details:perl core_switch.pl <Device IP>\n"; print "Ex: perl core_switch.pl 192.168.3.10\n"; exit; } my $ip = $ARGV[0]; print "=============================================================== +============\n"; print "Device IP:$ip\n"; #Connecting to Cisco Device my $session = Net::Telnet::Cisco->new(Host => $ip, Dump_Log => "dump.l +og"); $session->login('xxxxx','xxxxxxxxxx'); #Executing the commands print "=============================================================== +============\n"; print "CPU process history\n"; my @process_history= $session->cmd('Show process cpu history'); print "@process_history\n"; print "=============================================================== +============\n"; $session->close;

In reply to Cannot connect to Cisco Device by bks

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.