Joep Gommers | 3 Nov 2003 14:07
Picon

[zebra 20635] Re: Net::Telnet module and ZebraB

Moyaze Shivji wrote:

>Hi
>
>I wonder if someone could please give me some advice on using the
>Net::Telnet module with Zebra.
>
>I am basically trying to run a script that will telnet to Zebra on port
>2605, enter the password, then enter the enable password, then go
>into configuration terminal mode (conf t) and then change the hostname of
>the bgpd daemon. Seems like a very trivial script to do but I am
>having problems making the script enter the enable password and am only
>able to enter the first password and issue a show command to the
>Zebra router. The script below just does that :
>
>#!/usr/bin/perl -w
>use Net::Telnet ();
>    $t = new Net::Telnet (Timeout => 10,
>                          );
>$host = "localhost";
>$passwd = "zebrapasswd";
>        $t->open(Host => $host,
>               Port => 2605);
>$t->print("$passwd");
> <at> lines = $t->cmd("show ip bgp sum");
>print  <at> lines;
>exit();
>
>
>I would be grateful if someone could provide some advice what needs to be
(Continue reading)

Gilad Arnold | 3 Nov 2003 15:46

[zebra 20639] Re: Net::Telnet module and ZebraB

Hi,

Joep Gommers wrote:

> Expects gives you the same features as Net::Telnet but it can wait for 
> e.g. Password: to arrive on the screen after wich it can send your password.

Here's a simple Expect script that logs in to a Cisco-like VTY 
(including password handling) and issues whatever sequence of 
configuration commands and output handling. Commands can be provided as 
command-line arguments or piped into the stdin.

(BTW: I wonder if the script handles a change of hostname in the telnet 
prompt... ;-> )

Gilad

#!/usr/bin/expect -f
if { $argc < 4 } {
	puts "Usage: cisco.expect HOST {USERNAME|'NONE'} {PASSWORD|'NONE'} {ENABLE-PASSWORD|'NONE'}
\[CMD \[...\]\]"
	exit
}
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set enable_password [lindex $argv 3]

(Continue reading)


Gmane