title: Send an email using shell script and appending the output from the query
body: <p>Below is my shell script from which I am running two Hive SQL queries. Which is working fine.</p>
  
  <pre><code>#!/bin/bash
  
  DATE_YEST_FORMAT2=`perl -e 'use POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*96);'`
  echo $DATE_YEST_FORMAT2
  
  hive -e "
  set mapred.job.queue.name=data-technology;
  SELECT SUM(total_items_purchased), SUM(total_items_missingormismatch) from lip_data_quality where dt='$DATE_YEST_FORMAT2';
  SELECT 100 * SUM(total_items_missingormismatch*1.0) / SUM(total_items_purchased) FROM lip_data_quality where dt='$DATE_YEST_FORMAT2';"
  </code></pre>
  
  <p>I am running the above shell script like this-</p>
  
  <pre><code>sh -x test.sh
  </code></pre>
  
  <p><strong>Problem Statement:-</strong></p>
  
  <p>If you see my first SELECT query, it will give me two columns as an OUTPUT, SUM of total_items_purchased and SUM of total_items_missingormismatch. And my second SELECT will give the percentage of those columns.</p>
  
  <p>I need to send these three details in an email using that above <code>SHELL SCRIPT</code>. Basically I need to send  these three things in an email.</p>
  
  <p>From the first query- I need to send-</p>
  
  <pre><code>total_items_purchased and total_items_missingormismatch
  </code></pre>
  
  <p>And from the second query- I need to send-</p>
  
  <pre><code>Percentage that I am calculating.
  </code></pre>
  
  <p>Email can be like this or some better approach-</p>
  
  <pre><code>Total Items Purchased:- Some Number
  Total Items MissingorMismatch:- Some Number
  Error Percentage:- Some Percentage
  </code></pre>
  
  <p>Any suggestions will be appreciated.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>After making changes in my Shell Script, I ran the below shell script-</p>
  
  <pre><code>#!/bin/bash
  
  QUERY1 = `hive -e "
  set mapred.job.queue.name=data-technology;
  SELECT SUM(total_items_purchased), SUM(total_items_missingormismatch) from lip_data_quality where dt='20120804';`
  
  QUERY2 = `hive -e "
  set mapred.job.queue.name=data-technology;
  SELECT 100 * SUM(total_items_missingormismatch*1.0) / SUM(total_items_purchased) FROM lip_data_quality where dt='20120804';"`
  
  echo "Total items purchased: `echo $QUERY1 | awk '{print $1}'`"
  echo "Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`"
  echo "Error Percentage: $QUERY2"
  </code></pre>
  
  <p><strong>Output that I got which I don't think is right? Something wrong with script? As I am running SunOS:</strong></p>
  
  <pre><code>bash-3.00$ sh -x emailtest.sh
  + hive -e
  set mapred.job.queue.name=data-technology;
  SELECT SUM(total_items_purchased), SUM(total_items_missingormismatch) from lip_data_quality where dt='20120804';
  + QUERY1 = 3443837 448750
  emailtest.sh: QUERY1: not found
  + hive -e
  set mapred.job.queue.name=data-technology;
  SELECT 100 * SUM(total_items_missingormismatch*1.0) / SUM(total_items_purchased) FROM lip_data_quality where dt='20120804';
  + QUERY2 = 13.030523802375084
  emailtest.sh: QUERY2: not found
  + awk {print $1}
  + echo
  + echo Total items purchased:
  Total items purchased:
  + awk {print $2}
  + echo
  + echo Total Items MissingorMismatch:
  Total Items MissingorMismatch:
  + echo Error Percentage:
  Error Percentage:
  </code></pre>
  
  <p>Few parts from the script are working fine, but the last three echo statements are not working fine I guess.</p>