Below is my shell script that is working fine.
#!/bin/bash
DATE_YEST_FORMAT2=`perl -e 'use POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*96);'`
echo $DATE_YEST_FORMAT2
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';"`
echo "Total items purchased: `echo $QUERY1 | awk '{print $1}'`"
echo "Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`"
echo "Error Percentage: $QUERY2"
I am running the above shell script like this below-
sh -x test.sh
Problem Statement:-
From the above shell script, I am getting below three things from the last three echo statements-
Total items purchased
Total Items MissingorMismatch
Error Percentage
I need to send all these above three things in an email to our email group we have DL-host@company.com
by using that shell script
above or suppose if I have 10 email list
to which I need to send email with the same contents and subjects, then I think, I can store all these 10 emails list in some variable and just read it from there and keep on sending, right?. Is this possible to do it? I was thinking email structure like this below, just making very simple.
Subject
Test Data
Mail Body
Total items purchased:- Some Number
Total Items MissingorMismatch:- Some Number
Error Percentage:- Some Number
Any thoughts will be appreciated.
Update, After trying larsks suggestions, I am getting only last echo statement in an email meaning only the error percentage one, not all three in a single email:-
#!/bin/bash
DATE_YEST_FORMAT2=`perl -e 'use POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*96);'`
echo $DATE_YEST_FORMAT2
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';"`
echo "Total items purchased: `echo $QUERY1 | awk '{print $1}'`"
echo "Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`"
echo "Error Percentage: $QUERY2" | mail -s "Test Data" rj@host.com