Skip to content

Instantly share code, notes, and snippets.

@xuwang
Last active June 28, 2016 00:17
Show Gist options
  • Save xuwang/43c21f787cdc2aed9447 to your computer and use it in GitHub Desktop.
Save xuwang/43c21f787cdc2aed9447 to your computer and use it in GitHub Desktop.
Pretty print JSON output on CoreOS
#!/usr/bin/bash
# This scrip uses toolbox that comes with CoreOS and runs python -m json.tool to parse JSON output.
# The script has pre-configured commands for common etcd api calls, but can take any commands that
# generate JSON output.
command="$@"
# Output directory shared into the toolbox
outputFile=/home/core/output.$$
toolboxFile=/media/root/$outputFile
help(){
echo "Usage: `basename $0` [members|leader|store|version][command with JSON output]"
exit 0
}
case "$command" in
member|members )
curl -L -s localhost:2379/v2/members > $outputFile
;;
leader|self|store)
curl -L -s localhost:2379/v2/stats/$command > $outputFile
;;
version)
curl -L -s localhost:2379/version
echo ""
;;
h|help)
help
;;
*)
[ ! -z "$command" ] && $command > /home/core/output.$$ || help
;;
esac
[ -f $outputFile ] && toolbox -q python -m json.tool $toolboxFile && rm -f $outputFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment