title: telnet automation script fails sometimes
body: <p>I am running the following simple telnet script which just logs into a machine and exits.</p>
  
  <p>The same script works fine (goes through 1000 iterations) from one Linux server but fails (consistently) from another Linux server (fails after say 200 attempts). </p>
  
  <p>In failure case, the number of iterations it takes to fail varies but failure is persistent.</p>
  
  <pre><code>#!/usr/bin/perl
  use Net::Telnet;
  
  my $loop = 0;
  my $dumpfile = "dump.log";
  my $inputfile = "input.log";
  
  for ($loop =1; $loop &lt;=1000; $loop++) {
          print "===============Loop: $loop =====================\n";
          $telnet = new Net::Telnet ( Timeout=&gt;20, Errmode=&gt;'die');
          print "$telnet\n";
          $telnet-&gt;open('sys-007');
          $telnet-&gt;dump_log($dumpfile);
          $telnet-&gt;input_log($inputfile);
          $telnet-&gt;waitfor('/login: $/i');
          $telnet-&gt;print('root');
          $telnet-&gt;waitfor('/Password:$/i');
          $telnet-&gt;print('007');
          sleep 2;
          $telnet-&gt;print('exit');
          print "=================================================\n";
  }
  </code></pre>
  
  <h1>Script exits with:</h1>
  
  <pre><code>pattern match read eof at ./telnettest.pl line 15 (i.e, waitfor('/login: $/i'); Line)
  </code></pre>
  
  <p>I tried the following to see what is going wrong:</p>
  
  <ol>
  <li><p>In the client machine: (sys-007)</p>
  
  <pre><code>tcpdump -nvvv -w test.txt host &lt;Server IP&gt;
  </code></pre></li>
  </ol>
  
  <p>strings test.txt has:</p>
  
  <h1>Successful attempt Log:</h1>
  
  <pre><code>sys-007 (ttyp0)
  ^Fl$4
  ^!^Fl$
  login: 
  ^Fl$4
  ^Fl$4
  root
  ^(^Fl*
  root
  bP"u
  ^Fl*4
  bP5u
  ^.^Fl*
  Password:
  ^Fl*4
  ^Fl*4
  007
  ^7^Fl6
  ^Fl64
  ^9^Fl6
  Terminal type? [xterm] 
  ^Fl64
  ^Fl64
  exit
  ^Fl&lt;4
  ^Fl&lt;
  exit
  ^Fl&lt;
  </code></pre>
  
  <h1>Failed Attempt:</h1>
  
  <pre><code>sys-007 (ttyp0)
  *^hn
  +^hn
  </code></pre>
  
  <p>No login: prompt!</p>
  
  <ol>
  <li><p>In server machine: (Linux Server)</p>
  
  <pre><code>[telnet@server]~% netstat --inet -a | grep telnet | grep sys-007
  
  There are no TIME_WAIT or CLOSE_WAIT sockets.
  </code></pre></li>
  </ol>
  
  <p>Please tell me what should I look for to find out what is going wrong.</p>