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

hi all, below is my script that telnet into a switch and i printed out all the lines from the start i logged in to the switch but it's taking me 1500secs to print out all the lines, why is it taking so long? lesser than 1500 secs the program timeout
#!perl\bin\perl use strict; use warnings; my $t; my @lines; my @ok; use Net::Telnet(); $t = new Net::Telnet(timeout=>1500); $t->open("ip_address"); $t->waitfor('/ENTER USERNAME < /i'); $t->print("username"); $t->waitfor('/ENTER PASSWORD < /i'); $t->print("password"); @ok = $t->getlines; print @ok;

Replies are listed 'Best First'.
Re: why is it taking so long to read all the lines in net::Telnet
by pc88mxer (Vicar) on Apr 22, 2008 at 04:06 UTC
    I have a feeling that your server is keeping the connection open after emitting the response for the TESTBED command. Thus, the call $t->getlines is terminating only because it is timing out, and with the timeout set to 1500 seconds, it's going to take that long for it to return. You probably will have to develop a test to tell when the server is finished with the TESTBED command and do something like:
    while (defined($_ = $t->getline)) { last if (...test for end of response...); push(@ok, $_); }
Re: why is it taking so long to read all the lines in net::Telnet
by ig (Vicar) on Apr 22, 2008 at 05:32 UTC
    I suspect your problem is that getlines "reads and returns all the lines of data from the object until end of file is read." and that getlines does not read end of file unless the remote end closes the telnet connection. In the mean time it waits and keeps reading any output produced, until it times out.

    Update: which is what pc88mxer already said, now that I read it again.

      hm...alright so is there any way i can make the program recognise after i type in my password, it returns the results to me immediately and not take such a long time?
        Yes, delete the line @ok = $t->getlines;