Skip to content

Instantly share code, notes, and snippets.

@malloc47 malloc47/cloudera-hosts.sh
Last active Oct 23, 2018

Embed
What would you like to do?
#!/bin/bash
read -p "environment: " env
read -p "user: " user
read -s -p "password: " password
if [ "$env" == "prod" ] ; then
url=http://manager.hadoop.werally.in:7180/api/v10/hosts
elif [ "$env" == "blue" ] ; then
url=http://manager.hadoop-bluesteel.werally.in:7180/api/v10/hosts
elif [ "$env" == "int" ] ; then
url=http://manager.hadoop-integration.werally.in:7180/api/v10/hosts
elif [ "$env" == "dev" ] ; then
url=http://manager.hadoop-dev.werally.in:7180/api/v10/hosts
else
echo -e "\nenv must be one of {prod|blue|int|dev}"
exit 1
fi
curl -u $user:$password $url \
| jq -r --arg env "$env" '.items | map({hostname:.hostname, alias:(.hostname | capture("(?<prefix>[a-z]*)").prefix)}) | sort_by(.hostname) | group_by(.alias) | map(to_entries | map({hostname:.value.hostname, alias:(.value.alias + ((.key+1) | tostring))})) | flatten | .[] | ("Host " + .alias + "-" + $env + "\n" + " HostName " + .hostname + "\n")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.