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

The below script works fine for me but with normal login, Actually i need to go with "enable 5" and with password "xxxx" to get the user details. So please any one help is here highly appreciated.

I am using Net::Telnet::Cisco

Here is my prompt for enable, Pleaes have look on it,

ERX02>enable 5 Password: ********** ERX02#
#!/usr/bin/perl use Net::Telnet::Cisco; #$rtrip = 'xx.xx.xx.xxx'; #$pass='support123'; sub juniperlogin { $rtrip = $_[0]; print "Logging into router $rtrip\n"; $session = Net::Telnet::Cisco->new(Host => $rtrip, Timeout => '30'); $session->login(Name => 'login', Password => 'support123', Prompt => ' +/ERX02>$/', Timeout => '30'); #$session->cmd(String => "set cli screen-length 0", Prompt => '/(?m:^\ +w+@[\w.-]+[>])/', Timeout => '30'); } sub junipercmd { $cmd = $_[0]; #@output = $session->cmd(String => "$cmd", Prompt => '/(?m:^\w+@[\w.-] ++[>])/', Timeout => '60'); @output = $session->cmd(String => "$cmd", Prompt => '/ERX02>$/', Timeo +ut => '60'); return @output; } &juniperlogin("1.1.7.1"); @output =&junipercmd("show version"); print @output;

Replies are listed 'Best First'.
Re: help needed
by tachyon-II (Chaplain) on Jun 08, 2008 at 07:19 UTC

    In junipercmd you have:

    Prompt => '/ERX02>$/' But in your example the prompt returned is ERX02#
    So it won't match, thus won't return command to your program. Try a simple ERXO2. You really only need to set this once. ***You probably don't even need to set it at all as there is an inbuilt default that should work***.

    As an aside you are obviously not using strict and passing things around as globals - this is bad. The logic for having subs that simply serve as more or less useless wrappers around the existing functions in Net::Telnet::Cisco eludes me. In your prompt RE you have @[ which will not be doing what you think it does, whatever that might be.

    Does this work:

    #!/usr/bin/perl use Net::Telnet::Cisco; use strict; my $rtrip = 'xx.xx.xx.xxx'; my $user = 'login'; my $pass = 'support123'; my $cmd = 'some command'; my $session = Net::Telnet::Cisco->new( Host => $rtrip, Prompt => '/ERX02/, Timeout => '30'); $session->login( Name => $login, Password => $pass, ); my @output = $session->cmd($cmd); print @output;
    690918
    by Mejaz (Novice) on Jun 08, 2008 at 12:57 UTC