0
以下是我正在運行兩個Hive SQL查詢的shell腳本。哪個工作正常。使用shell腳本發送電子郵件並附加查詢輸出
#!/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';"
我運行上面的shell腳本喜歡這個 -
sh -x test.sh
問題陳述: -
如果你看到我的第一個SELECT查詢,它會給我兩列作爲OUTPUT,total_items_purchased的總和和total_items_missingormismatch的總和。而我的第二個SELECT將給出這些列的百分比。
我需要在電子郵件中使用上述SHELL SCRIPT
發送這三個詳細信息。基本上我需要通過電子郵件發送這三件事。
從第一查詢 - 我需要發送 -
total_items_purchased and total_items_missingormismatch
而且從第二查詢 - 我需要發送 -
Percentage that I am calculating.
電子郵件可以是這樣的或者一些更好approach-
Total Items Purchased:- Some Number
Total Items MissingorMismatch:- Some Number
Error Percentage:- Some Percentage
任何建議,將不勝感激。
更新:
在我的Shell腳本進行更改後,我跑到下面的外殼腳本 -
#!/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"
輸出,我得到了,我不認爲這是正確的?腳本有問題嗎?由於我運行SunOS:
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:
從劇本少部分工作正常,但最後三個echo語句不工作細,我猜。
感謝Mike的建議我試過了,我已經用我正在運行的腳本和輸出的問題更新了問題,我猜測腳本有問題。或者可能是'awk'?當我運行'SunOS' .. – ferhan 2012-08-08 22:34:00
幾部分工作正常,但最後三個回聲陳述無法正常工作。有什麼建議麼? – ferhan 2012-08-08 22:38:57
修改代碼以反映修復。 – 2012-08-08 23:24:38