1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #!/bin/bash ZK_HOST="192.168.25.123:2181"
topics=`cat ./topic.txt`
IFS=$'\n' echo '{"version":1,"partitions":[' > topic-reassignment.json for i in $topics;do echo 'write file for '$i'' leaders=`./kafka-topics.sh --zookeeper $ZK_HOST -describe --topic $i|grep Leader` for leader in $leaders;do partition=`echo $leader |awk '{print $4}'` leader=`echo $leader |awk '{print $6}'` follwer=`grep -vxF $leader ./leaders.txt` follwer1=`echo $follwer | awk '{print $1}'` follwer2=`echo $follwer | awk '{print $2}'` echo '{"topic":"'$i'","partition":'$partition',"replicas":['$leader','$follwer1','$follwer2']},' >> topic-reassignment.json done done echo ']}' >> topic-reassignment.json
|