title: Bash Script to Automate Telnet
body: <p>I'm trying to automate telnet, using this command which works great</p>
  <pre><code>echo -e &quot;\x1dclose\x0d&quot; |
    telnet abc.gc.ca 100 |
    grep Connected&gt;/dev/null &amp;&amp; printf &quot;PASSED\n&quot; || printf &quot;FAILED\n&quot;
  </code></pre>
  <p>But if I put it in a script, it just hangs and I have no idea why.</p>
  <pre><code>#!/bin/bash
  
  SERVERS=(
     &quot;abc.gc.ca 100&quot;
     &quot;defg.gc.ca 101&quot;
     &quot;123.gc.ca 102&quot;
     &quot;xyz.gc.ca 103&quot;
  )
  
  for host in ${SERVERS[@]}; do
    echo -e &quot;\x1dclose\x0d&quot; |
      telnet $host |
      grep Connected &gt; /dev/null &amp;&amp; printf &quot;PASSED\n&quot; || printf &quot;FAILED\n&quot;
  done
  </code></pre>