title: Execute script over SSH and get output?
body: <p>I am trying to execute a command in a remote machine and get the output.</p>
  
  <p>I have tried implementing below shell script but unable to get the content.</p>
  
  <pre><code>#!/bin/bash
  
  out=$(ssh huser@$source &lt;&lt; EOF
  while IFS= read -r line
  do
  echo 'Data : ' $line
  done &lt; "data.txt"
  EOF
  )
  
  echo $out
  </code></pre>
  
  <h2>Output:</h2>
  
  <pre><code>Data : Data : Data : 
  </code></pre>
  
  <p>I could see the "Data :" is printed 3 times because the file "data.txt" has 3 lines of text.</p>
  
  <p>I can't use scp command to get the file directly because I might have to run some command in the place of text file.</p>
  
  <p>Can someone help me in finding the issue?</p>
  
  <p>Thanks in advance.</p>