Well, first I think you shouldn't be using login with waitfor. You'll use print because waitfor captured the prompt and I don't think login will see it after that.

Second, you missed the whole point of using a regex there. If you read the Net::Telnet documentation on waitfor, you'll see that

my ($prematch, $match)= $obj->waitfor($matchop);
gives you the string that matched in $match. So, if you use a regex like /(Password|Username)/ and a list assignment (again, I got this straight from the documentation for the module), then $match tells you whether you need to $obj->print a password or username string. Naturally if you print a username, you should then waitfor the password prompt and print the password. login attempts to simplify this stuff, but it's extremely picky about what it expects to see.

Your code needs to do the job of login, not try to work alongside it. A direct quote from the login section of Net::Telnet: "Consider using a combination of print() and waitfor() as an alternative to this method when it doesn't do what you want, e.g. the remote host doesn't prompt for a username."


In reply to Re^3: Net telnet Cisco Login by ssandv
in thread Net telnet Cisco Login by sout11

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.