Adventures in Bash: Consume Last N messages from a kafka topic on the command line

This came up while I was helping a developer debug their service. The kafka shell tools are functional, but not super well documented or easy to use. This tail -n 10 type use case is insanely difficult to achieve with just the shell tools, especially if you want human readable timestamps on messages. I realize this code isn't the cleanest, but I had fun writing it and it works like a champ on our 0.10.x Kafka brokers.

Since this script uses the kafka.tools.GetOffsetShell tool, which accepts timestamps as input it could somewhat easily be adapted to display all messages between two given timestamps.