Last active
August 29, 2015 14:08
-
-
Save dgertych-monterail/3e8704960acaf4db6108 to your computer and use it in GitHub Desktop.
Get random HipChat IP and modify /etc/hosts
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
#!/usr/bin/env bash | |
set -e | |
rand() { | |
printf $(( $1 * RANDOM / 32767 )) | |
} | |
rand_element () { | |
local -a th=("$@") | |
unset th[0] | |
printf $'%s\n' "${th[$(($(rand "${#th[*]}")+1))]}" | |
} | |
echo "* Downloading list of HipChat IPs" | |
ips=($(curl --progress-bar https://www.hipchat.com/help/networking | grep -Eo "(([0-9]{1,3}\.){3}[0-9]{1,3})")) | |
selected_ip="$(rand_element ${ips[*]}) chat-main.hipchat.com" | |
echo "* Selected IP: $selected_ip" | |
echo "* Modify /etc/hosts" | |
sudo sed -i '' '/chat-main.hipchat/d' /etc/hosts | |
echo $selected_ip | sudo tee -a /etc/hosts > /dev/null | |
echo "* Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the one-liner below to run it locally:
curl -fsSL http://bitly.com/10wDsM7 | bash