title: Output of SQL query and command to a file in shell script
body: <p>I have the following shell script which runs a SQL query and a command  which sends the output as an email. The issue is I am able to send only the SQL output. Not the output of the for loop. I tried to give the "EOF" after the for loop but then it gives a syntax error. Please let me know how to send both the output in an email.</p>
  
  <p>Thanks &amp; Regards,
  Akhil</p>
  
  <pre><code>#!/bin/bash
  source $HOME/.bash_profile
  
  cd /home/cron
  
  wfVAR="red blue green"
  
  
  echo " " &gt; /home/cron/output.lst
  sqlplus -s user/test@DB &lt;&lt;EOF
  set linesize 55 pages 500
  spool output_temp.lst;
  set head off;
  select sysdate from dual;
  set head on;
  spool off;
  EOF
  
  for name in ${wfVAR}; do
    pmcmd getworkflowdetails -sv REPOSITORY ${name} | grep -e "Workflow:" -e "Workflow run status:" -e "End time:"
   done
  
  sed -e 's/ *$//' output_temp.lst &gt; output.lst
  cat /home/cron/output.lst | mail -s "Output - `date '+%d-%m-%y'`" akhil@gmail.com
  rm output_temp.lst
  </code></pre>