I'm working with kafka and I want to monitor topics. Basically I output several topics to stdout and to file for later review. For single topic monitoring I came up with the following command:
${KAFKA_HOME}/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic mytopic | \
while IFS= read -r line; do
printf '[%s | %20s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "mytopic" "${line}";
done | tee -a kafka.out
However, there're many topics to consume, so I'm trying to do something like
consumer=${KAFKA_HOME}/bin/kafka-console-consumer.sh
mapfile -t topics < <(${KAFKA_HOME}/bin/kafka-topics.sh --zookeeper localhost:2181 --list)
for i in ${topics[@]}; do
xterm -T ${i} -e "my_command" &
done
tail -F kafka.out
where my_command is the above command. It doesn't work. I suspect I'm messing up with quotes, unfortunately I can't figure out how to apply them correctly
show_topicthat takes the topic as a parameter. Then yourxtermline becomes a simplexterm -e "show_topic $i"and you avoid the whole quoting mess.