Skip to content

Instantly share code, notes, and snippets.

@malloc47
Last active October 23, 2018 15:51
Show Gist options
  • Save malloc47/fb5763801697572a166585b770243f1a to your computer and use it in GitHub Desktop.
Save malloc47/fb5763801697572a166585b770243f1a to your computer and use it in GitHub Desktop.
#!/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