in reply to Telnet into Cisco switches

I've used it too. This is a snippet from my first perl script (that did anything useful).

my $cs = new Net::Telnet::Cisco ( Errmode => "return", Timeout => 100, Prompt => '/>/' ); $cs->open("$ubr"); $cs->login( $userid, $password); $cs->cmd( 'terminal length 0'); @lines = $cs->cmd( "show cable modem | inc $mac" ); foreach my $line (@lines) { chomp $line; $line =~ s/ +/ /g; my @values=split(/ /,$line); push(@scmresults,@values); }

~~
naChoZ

Replies are listed 'Best First'.
Re: Re: Telnet into Cisco switches
by primus (Scribe) on Jul 11, 2003 at 15:32 UTC
    thanks for the replies, but i am running into a login error... i tried to do $session->login(Password => $switch->{PASS1}); but doesnt login complaining about a bad password or something... when i do it by hand it works with that password, also there is no username, it just presents you with a password prompt.

    does it make a difference if i do:
    if ($session->login(Password => $switch->{PASS1})) {}
    of just:
    $session->login(Password => $switch->{PASS1});

      I am being lazy for the moment and not looking at the man page for Net::Telnet or Net::Telnet::Cisco.

      There is a way to get Net::Telnet to write an audit log of the conversation between your script and the device. If you invoke that you might get some idea of what is going wrong.


      Peter L. BergholdBrewer of Belgian Ales
      Peter@Berghold.Netwww.berghold.net
      Unix Professional
        Yes, look into the dump_log:
        dump_log - log all I/O in dump format $fh = $obj->dump_log; $fh = $obj->dump_log($fh); $fh = $obj->dump_log($filename);


        "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      Are there any oddball chars you may need to escape?

      ~~
      naChoZ

        nope :(
      here is my code, in case i am missing something obvious:
      my $session; $session = Net::Telnet::Cisco->new(Host => $switch->{IP}); $session->login(Password => $switch->{PASS1}); $session->close();

        Is the prompt from the switch what Net::Telnet::Cisco thinks it should be?


        Peter L. BergholdBrewer of Belgian Ales
        Peter@Berghold.Netwww.berghold.net
        Unix Professional
        Yes, you are.

        $session->login(Password => $switch->{PASS1});

        login needs both username and password.

        ~~
        naChoZ

        nachoz, i tried
        $session->login(undef,'password');
        because there is no username for the login, just a password, but that did not work. and the router has a prompt
        router> router# router$
        so is that okay?
      well, i think that the login routine they provide should work, i mean in the documentation they state, "All arguments are optional as of v1.05. Some routers don't ask for a username, they start the login conversation with a password request." so i mean i think it should work just supplying the password.
        Ah, ok, Didn't catch that. I haven't used it since approx 1.04. Did you try having it print the password to the screen 1st?

        ~~
        naChoZ

      okay all, i must appologize... but i hope you find this alittle humerous:

      turns out the system admin mistyped the password my script was using... silly error.

      sorry again
      well i tried even to hardcode the password in, and still no go...
      $session->login(Password => 'password');
      yea... it prints fine to the screen
        Sorry to beat this horse to death, but I just want to make sure of this, did you surround it so that you could make sure there weren't any extra spaces or chars in it? I usually do something like:

        print "-->$foo<--\n";

        So if there's a trailing space, for instance, it will output:

        -->bar <--

        ~~
        naChoZ

      well, i suppose i could give it a shot, but the file it is being read from has not spaces, "ipaddress,password"

      and i chomp that when i read it in to get rid of the newline, also, i tried the password manually, $session->login(Password => 'password'); so i dont know how there could be a space...