title: How to capture the output of telnet command in a variable in Shell script
body: <p>I need to run the telnet command on a remote server using shell script and have to capture the output. When i execute the below, it is not getting completed but instead getting hung. Can someone please advise how to terminate or timeout the telnet command using shell script once it is executed.</p>
  <pre><code>telnet_output=`telnet $server $port`
  echo &quot;Output is $telnet_output&quot;
  </code></pre>
  <p>I tried writing it to a file as well. But this is also getting hung when executed in remote server.</p>
  <pre><code>opfile=&quot;telop.log&quot;
  telnet_output=`telnet $server $port | tee $opfile`
  op=`cat $opfile`
  echo &quot;$op&quot;
  </code></pre>