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

I tried this, but it ends the session and logs me out.

How can I code this to leave me logged in at the command prompt?

#!/usr/bin/perl use Net::Telnet::Cisco ; my $switch = $ARGV[0] ; print "$switch \n" ; my $session = Net::Telnet::Cisco->new(Host => 'ba1-1'); $session->login('charlie', 'letmein'); # Enable mode if ($session->enable("letmein") ) { @output = $session->cmd('show privilege'); print "My privileges: @output\n"; } else { warn "Can't enable: " . $session->errmsg; }
This code works - it gives me the following output:
[charlie@ion1 bin]$ goto ba1-1 ba1-1 My privileges: Current privilege level is 15 [charlie@ion1 bin]$

Thanks!

Charlie

Replies are listed 'Best First'.
Re: Telnet to Cisco command prompt...
by Illuminatus (Curate) on Sep 24, 2008 at 17:21 UTC
    Please use the code tag for code:
    #!/usr/bin/perl use Net::Telnet::Cisco ; my $switch = $ARGV[0] ; print "$switch \n" ; my $session = Net::Telnet::Cisco->new(Host => 'ba1-1'); $session->login('charlie', 'letmein'); if ($session->enable("letmein") ){ @output = $session->cmd('show privilege'); print "My privileges: @output\n"; } else { warn "Can't enable: " . $session->errmsg; }
    Given this, I do not understand your question. Why do you think that you are still not logged in? If this is the end of the script, then of course you will no longer be logged in. The telnet session is within the context of the perl script. Once the perl script ends, the telnet session goes away.

    If there is more to the script that you have not provided that seems to indicate that the login has terminated, I/we need to see it.

      I would like to create a "goto" script. I want to have the script leace me at the Cisco's command prompt. The script I have listed above logs me out when it completes. Rather than going through the user, pwd, en, pwd routine each time, I want to be able to execute the script and have it leave me in the enable mode. Thanks for any help! Charlie
        Sorry, you can't do that this way. The best you could do using this approach is to essentially write your own pass-through code after your login. It would read your info from stdin, package it as commands, use the perl interface to execute it and display the results.