码迷,mamicode.com
首页 > 系统相关 > 详细

使用shell读取文本文件发送到kafka

时间:2018-01-17 20:17:55      阅读:1792      评论:0      收藏:0      [点我收藏+]

标签:nbsp   color   gpo   定义   shell   注意   很多   console   参数   

#!/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

 

使用shell读取文本文件发送到kafka

标签:nbsp   color   gpo   定义   shell   注意   很多   console   参数   

原文地址:https://www.cnblogs.com/30go/p/8304875.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!