Last active
August 29, 2015 14:18
-
-
Save vanjos/89f64ff5655f63a87742 to your computer and use it in GitHub Desktop.
A quick and dirty CCM ethernet aliasing program
This file contains 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 | |
# ------------------------------------- | |
# Quick and dirty to set up cassandra | |
# CCM with alias'ed ethernet addresses | |
# ------------------------------------- | |
# | |
# ===== # | |
# ARGS # | |
# ===== # | |
# | |
# The only argument is location of .ccm directory | |
EXPECTED_ARGS=1 | |
[ x$1 == "x-h" ] || [ x$1 == "x--help" ] || [ $# -gt $EXPECTED_ARGS ] && \ | |
echo && \ | |
echo "USAGE FOR $0" && \ | |
echo "===============================================================================================" && \ | |
echo "$0 <location of .ccm directory - USUALLY ~/>" && \ | |
echo && \ | |
echo " example: $0" && \ | |
echo " $0 ~/" && \ | |
echo " $0 /opt/ccm/.ccm" && exit | |
[ "$1" ] && DIR="$1/.ccm" || DIR="$HOME/.ccm" | |
# ========== # | |
# PROGRAM # | |
# ========== # | |
# | |
# The interface that is aliased | |
ETH=$(ifconfig -a | grep -oP '^\w+(?=:\d)' | uniq) | |
for yaml in $(find $DIR/$(cat $DIR/CURRENT)/ -name cassandra.yaml); do | |
nodenum=$(echo $yaml | grep -oP '(?<=node)\d+') | |
address=$(ifconfig $ETH:$nodenum | grep -oP '(?<=addr:)(\d+\.)+\d+(?=\s)') | |
sed -i "/listen_address:/c\listen_address:$address" $yaml | |
echo "CHANGED NODE $nodenum ($yaml) TO LISTEN ON: $address" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment