expect telnet unexpected delays

I must automatically monitor and manage a large number of boxes on our network.

I have been using perl/Net::Telnet and expect/telnet and also perl/ssh and expect/ssh to reach the command line of the remote boxes. Scripts are working but slow.

(Yes, I do use SNMP also but many boxes do not speak SNMP)

I believe that there is some protocol or terminal negotiating that I may be ignoring that blocks when the remote box sends a query and I do not respond.

I tried to read the RFC on Telnet which appeared to have an infinite number of options. My application is very simple: get to the remote command line.

Here is an example of expect/ssh (telnet exactly the same result) that includes unexpected data then the remote blocks for 10 seconds (local or remote default timeout?) then continues with expected response.

expect: set expect_out(buffer) "admin@10.100.72.223's password:"
send: sending "xxxxx\r" to { exp4 }
(logo deleted)
  MikroTik RouterOS 3.20 (c) 1999-2009       http://www.mikrotik.com/

  ^[[?62;9;c^[[39;3Rexpect: timed out

expect: does " \r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\n\r  MMM      MMM     
(expected data deleted)
   MikroTik RouterOS 3.20 (c) 1999-2009       http://www.mikrotik.com/\r\n\r\r\n\r
\u001b[9999B\r\u001b[9999B\u001bZ  \u001b[6n" (spawn_id exp4) match glob 
pattern " > "? no

You see I was looking for the prompt, " > ", which does appear 10 seconds later!

Part does appear to be a terminal command. I have to guess the remote box is asking me a question and I am failing to answer.

Surprising is that using ssh rather than Telnet gives the same results.
Manual use of ssh or Telnet = no delays.
Script use of ssh or Telnet = 10 second delays for each send/expect cycle!

Can some one give me a clue???

10 seconds is the standard delay for expect. You tell expect to expect something, so expect waits 10 seconds. If it doesn't see it in 10 seconds, it goes to the next line.

That bit of code you posted doesn't make sense to me.
To me it should look like:

 expect password:
send xxxxxxx\r
expect ">"

[quote=system shock;302315605]
10 seconds is the standard delay for expect. You tell expect to expect something, so expect waits 10 seconds. If it doesn't see it in 10 seconds, it goes to the next line.

That bit of code you posted doesn't make sense to me.
----------------------------------------------------------------------
Thanks rapid response.
I should have been more clear: I posted the log output NOT the script!
Used the code flag to preserve format.

I think you are saying expect always waits the full timeout period!

If this is the case then I still have a problem. I am dealing with thousands of boxes and unless I go to parallel processing I will never get around to all the boxes! Most respond in a second or so but some can take a few seconds if busy. So how do I set my timeout??? If I leave it at the default then that is 10,000 x n seconds where n is the number of send/expect cycles!

I was expecting that the remote box would respond to a command and expect would continue to the next operation immediately upon receipt of the expected response! But I do not see the expected response in the log file until after the timeout has occurred.