Skip to content

Instantly share code, notes, and snippets.

@davidmlentz
Created March 5, 2020 17:23
Show Gist options
  • Save davidmlentz/b72682ac63e0e771f4a5750a84ba276f to your computer and use it in GitHub Desktop.
Save davidmlentz/b72682ac63e0e771f4a5750a84ba276f to your computer and use it in GitHub Desktop.
Get JSON output from all commands from the local ZooKeeper AdminServer
#!/bin/bash
curl http://localhost:8080/commands | sed 's/^\(.*\)commands\(.*\)">\(.*\)$/curl http:\/\/localhost:8080\/commands\2/g' | sed 's/<br\/>//g' | sort | uniq > allcommands
counter=0
# TODO: scoping problem and I can't use this inside the while loop:
#commandcount=`wc -l allcommand | cut -d' ' -f1`
echo "{"
while read -r line; do
commandcount=18 # TODO: don't hardcode this
counter=$((counter+1))
command=$(echo $line | sed 's/^\(.*\)commands\/\(.*\)$/\2/g')
if [[ ! -z "$command" ]]; then
echo "\"$command\": [" # To print a header before the output of each cmd
$line
echo "]"
if [[ "$counter" -lt "$commandcount" ]]; then
echo ","
fi;
printf "\n\n"
fi;
done < allcommands
echo "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment