#!/bin/sh
## 參數定義
dt=`date +"%Y%m%d" -d "-1 days"`
outpath=/xxxx_log_${dt}.txt
brokerlist=192.168.1.100:9092,192.168.1.101:9092,192.168.1.102:9092
echo $dt $outpath $brokerlist
## 查詢hive表,輸出文件到指定路徑
hive -e "select name,age from test" > ${outpath}
## 判斷文件大小,如果大於0,則加載文件,寫入kafka
## 注意 結尾的 | > out.txt要加上,否則會出現很多奇怪的大於號
fileSize=`du -b ${outpath} | awk '{print $1}'`
if [ $fileSize -gt 0 ] then
cat ${outpath} | ./kafka_2.11-1.0.0/bin/kafka-console-producer.sh --broker-list ${brokerlist} --sync --topic test1 | > out.txt fi