Last active
April 12, 2016 20:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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