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

#!/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
原文地址:https://www.cnblogs.com/30go/p/8304875.html