Skip to content

Instantly share code, notes, and snippets.

@vanjos
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanjos/89f64ff5655f63a87742 to your computer and use it in GitHub Desktop.
Save vanjos/89f64ff5655f63a87742 to your computer and use it in GitHub Desktop.
A quick and dirty CCM ethernet aliasing program
#!/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