Kedar_Bhatia has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to login to a route server using below script when i execute my script it just doesnt do anything. I am doing this on a linux machine, idealy i should see a login prompt of the router.
use Net::Telnet::Cisco; my $session = Net::Telnet::Cisco->new(Host => '67.17.81.28', Port => +'23', Timeout =>'100');

Replies are listed 'Best First'.
Re: Telnet to server
by toolic (Bishop) on Oct 28, 2014 at 15:10 UTC
    The code you posted only shows that you constructed an object. You need to now call some methods to execute commands. From the Net::Telnet::Cisco SYNOPSIS:
    use Net::Telnet::Cisco; my $session = Net::Telnet::Cisco->new(Host => '123.123.123.123'); $session->login('login', 'password'); # Execute a command my @output = $session->cmd('show version'); print @output;
Re: Telnet to server
by cebundy (Novice) on Oct 28, 2014 at 19:18 UTC
    You can also tell Net::Telnet what prompt to look for. A description is in the POD of Net::Telnet.
    use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/bash\$ $/'); $t->open("sparky"); $t->login($username, $passwd); @lines = $t->cmd("who"); print @lines;
Re: Telnet to server
by Kedar_Bhatia (Initiate) on Oct 30, 2014 at 16:55 UTC
    Thanks guys ..Ok i got something working. I was able to login to router and get the command to execute on router and print output But the program just executes the command and returns to my bash prompt. I want to stay logged in to the router to do my tasks. How do I keep the router prompt from returning back to the my bash shell I ran the below code
    use Net::Telnet::Cisco; my $session = Net::Telnet::Cisco->new(Host => '192.168.25.133', Port + =>'2002'); my @ok = $session->login(); my @output = $session->cmd('sh ver'); print @output;
      Hi
      You could check the first reply to this post on telnet error handling in your particular case.Trapping errors in Net::Telnet::Cisco
      As you might be aware Some routers dont allow users to logon using telnet for security reasons, and if they do for operational reasons, there might even be restictions on what type of commands can be used.
      Having said that i see you were able to have some kind of a handshake with the router, so i guess its trial and error for you now.
      All the best

      The temporal difficulty with perl is u need to know C well to know the awesome.else u just keep *using* it and writing inefficient code