title: Make a Simple Pie Graph using Bash Shell Script
body: <p>Below is my Bash Shell Script from which I am executing my two Hive SQL Queries which is working fine. And I am calculating <code>Error Percentage</code> in this Bash Shell Script.</p>
  
  <pre><code>#!/bin/bash
  
  QUERY1=`hive -e "
  set mapred.job.queue.name=hdmi-technology;
  SELECT SUM(total_items_purchased), SUM(total_items_missingormismatch) from lip_data_quality where dt='$DATE_YEST_FORMAT2';"`
  
  QUERY2=`hive -e "
  set mapred.job.queue.name=hdmi-technology;
  SELECT 100 * SUM(total_items_missingormismatch*1.0) / SUM(total_items_purchased) FROM lip_data_quality where dt='$DATE_YEST_FORMAT2';"`
  
  
  mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@host.com rj@host.com  &lt;&lt;EOF
  Data Successfully loaded into LIP_DATA_QUALITY table
  
  Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`
  
  Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`
  
  Error Percentage: $QUERY2
  EOF
  </code></pre>
  
  <p><strong>Problem Statement:-</strong></p>
  
  <p>I will be getting <code>Error Percentage</code> number in <code>$QUERY2</code>. I need to make a Simple Pie Graph that can show <code>Error Percentage</code> and <code>No Error Percentage</code> by using the number from <code>$QUERY2</code> just like below graph using Bash Shell Script.</p>
  
  <p><img src="https://i.stack.imgur.com/sqdt6.png" alt="enter image description here"></p>
  
  <p>I am running <code>SunOS</code>. Is this possible to do in Bash Shell script? Any thoughts will be appreciated.</p>
  
  <p><strong>Update:-</strong></p>
  
  <p>Below is the Shell Script that I am using, that I created using <code>vi editor</code>.</p>
  
  <pre><code> 1  #! /bin/bash
   2
   3  TEMP=$(mktemp -t chart)
   4  QUERY1=36
   5  QUERY2=64
   6  cat &gt; $TEMP &lt;&lt;EOF
   7      &lt;html&gt;
   8        &lt;head&gt;
   9          &lt;!--Load the AJAX API--&gt;
  10          &lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt;
  11          &lt;script type="text/javascript"&gt;
  12
  13            // Load the Visualization API and the piechart package.
  14            google.load('visualization', '1.0', {'packages':['corechart']});
  15
  16            // Set a callback to run when the Google Visualization API is loaded.
  17            google.setOnLoadCallback(drawChart);
  18
  19            // Callback that creates and populates a data table,
  20            // instantiates the pie chart, passes in the data and
  21            // draws it.
  22            function drawChart() {
  23
  24              // Create the data table.
  25              var data = new google.visualization.DataTable();
  26              data.addColumn('string', 'Title');
  27              data.addColumn('number', 'Value');
  28              data.addRows([
  29                ['Error Percentage', $QUERY1],
  30                ['No Error Percentage', $QUERY2]
  31              ]);
  32
  33              // Set chart options
  34              var options = {'title':'Errors',
  35                             'width':400,
  36                             'height':300};
  37
  38              // Instantiate and draw our chart, passing in some options.
  39              var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  40              chart.draw(data, options);
  41            }
  42          &lt;/script&gt;
  43        &lt;/head&gt;
  44
  45        &lt;body&gt;
  46          &lt;!--Div that will hold the pie chart--&gt;
  47          &lt;div id="chart_div"&gt;&lt;/div&gt;
  48        &lt;/body&gt;
  49      &lt;/html&gt;
  50      EOF
  51
  52      # open browser
  53      case $(uname) in
  54         Darwin)
  55            open -a /Applications/Google\ Chrome.app $TEMP
  56            ;;
  57
  58         Linux|SunOS)
  59            firefox $TEMP
  60            ;;
  61       esac
  62
  </code></pre>
  
  <p>Error that I got after running the above shell script as <code>sh -x chart.sh</code>-</p>
  
  <pre><code>bash-3.00$ sh -x chart.sh
  chart.sh: syntax error at line 3: `TEMP=$' unexpected
  </code></pre>
  
  <p>Any thoughts will be appreciated.</p>
  
  <p><strong>Another Update:-</strong></p>
  
  <p>After the below suggestions, when I tried something like this-I got another error.</p>
  
  <pre><code>bash-3.00$ bash -x chart.sh
  ++ mktemp -t chart
  mktemp: failed to create file: /tmp/chart
  + TEMP=
  + QUERY1=36
  + QUERY2=64
  + cat
  chart.sh: line 6: $TEMP: ambiguous redirect
  </code></pre>
  
  <p>Another Update: Made Some Progress I guess. Not sure where the output files will be going? Or it will open into a browser?</p>
  
  <pre><code>bash-3.00$ bash -x chart.sh
  ++ mktemp -t chart
  + TEMP=/tmp/chart
  + QUERY1=36
  + QUERY2=64
  + cat
  ++ uname
  </code></pre>