title: Batch script to connect via SSH, execute a command and pass the results to an OUTPUT file
body: <p>I realize the query is simple and there are a lot of similar topics around the internet, but for some reason I cannot make this work and I am at its very end.</p>
  
  <p>This is the scenario. A batch script will connect (using putty link) to a Host. It will execute a command (like check Host version). The script will bring the output to a file.</p>
  
  <p>So far I was able to configure most of it - my script uses a pool - source file that holds the IPs, to read the Hosts it needs to connect to; it connects to the hosts; executes the check version command and it saves the result to a file.
  However, the result has a bad format and I am not able to bring the format I would like to see in the output file.</p>
  
  <p>This is my code:</p>
  
  <pre><code>:Var
  set out=E:\output.txt
  set src=E:\servers.txt
  set ver=cat /etc/*-release
  set creds=-l root -pw root
  set host=hostname
  :Cond
  for /f %%i in (%src%) do call :Cmd %%i
  :Cmd
  plink -ssh %1 %creds% %host%
  plink -ssh %1 %creds% %ver%
  echo %1 is %ver% &gt;&gt; %out%
  </code></pre>
  
  <p>The result is something like this:</p>
  
  <pre><code>server01Red Hat Enterprise Linux Server release 5.7 Beta (Tikanga)
  server02Red Hat Enterprise Linux Server release 5.7 Beta (Tikanga)
  </code></pre>
  
  <p>So I would like to make it properly formatted, for example:</p>
  
  <pre><code>server01 OS:Red Hat Enterprise Linux Server release 5.7 Beta (Tikanga)
  server02 OS:Red Hat Enterprise Linux Server release 5.7 Beta (Tikanga)
  </code></pre>
  
  <p>Or even to be able to truncate the output of the command that was ran at the host and display only part of it like "Red Hat" only for example.</p>
  
  <p>Thank you!</p>