Skip to content

Instantly share code, notes, and snippets.

@aerostitch
Last active April 12, 2016 20:49
Show Gist options
  • Save aerostitch/c60bf412abc0c38844b6 to your computer and use it in GitHub Desktop.
Save aerostitch/c60bf412abc0c38844b6 to your computer and use it in GitHub Desktop.
I know there are a lot cleaner ways to do that, I just had to do that for a 1 time rush on a really bare server so bash recurse to list all the zk nodes there
#!/bin/bash
# I know there are a lot cleaner ways to do that, I just had to do that for a 1 time rush on a really bare server
# so bash recurse to list all the zk nodes there
list_children ()
{
if [ $# -le 0 ]
then
return
fi
current_node=$1
echo $current_node
echo "ls $current_node" |/opt/zookeeper/bin/zkCli.sh | awk 'BEGIN {FS="(, )"} /^\[.*\]$/ {for (i = 1; i <= NF; i++) { gsub("\\\[|\\\]","") ; printf "%s\n", $i }}' 2>/dev/null | while read node
do
list_children "${current_node%/}/${node}"
done
}
list_children "/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment