shell脚本利用python随机模块生成随机数,并将数据发送到kafka中
#!/usr/bin/bash
# author :seed
i=1
while(( i <= 100 ))
do
res=$(python -c 'import random;print random.randint(10,20)')
echo $res
echo "zhangfei_$res">>../sanguoyanyi
echo "zhangfei_$res" | kafka-console-producer --topic cs_ --broker-list \
test94.AAAA.com:9092,test94.BBBB:9092,test94.CCCC.com:9092
let "i += 1"
sleep 2
done
echo "sum=$i"
转载于:http://blog.sina.com.cn/s/blog_6dd718930102xddk.html