Skip to content

Instantly share code, notes, and snippets.

@bradfordpythian
Created December 13, 2016 15:39
Show Gist options
  • Save bradfordpythian/c60734a10516943ccdc661f3cae5affc to your computer and use it in GitHub Desktop.
Save bradfordpythian/c60734a10516943ccdc661f3cae5affc to your computer and use it in GitHub Desktop.
Tungsten Cluster column trepctl output
#!/bin/sh
#
# NAME: cluster_trepctl.sh
# AUTHOR: Ronald Bradford
# PURPOSE: Simple script to combine trepctl output from 'n' hosts into columns
SCRIPT_NAME=`echo $0 | sed -e "s/\.sh$//"`
[ -z "${TMP_DIR}" ] && TMP_DIR="/tmp"
[ $# -eq 0 ] && echo "USAGE: $0 <host> [<host> ...]" && exit 0
if [ -z "${SSH_INFO}" ]
then
echo "No \$SSH_INFO defined... generating SSH information from vagrant"
SSH_INFO=${TMP_DIR}/${SCRIPT_NAME}."hosts".$$
vagrant ssh-config > ${SSH_INFO}
fi
# Get first hosts output, this has the column prefix
HOST=$1; shift
ssh -F ${SSH_INFO} ${HOST} "sudo su - tungsten -c 'trepctl status'" > ${TMP_DIR}/${SCRIPT_NAME}.$$.${HOST}
# For each other host, ignore the first column
while [ $# -gt 0 ]
do
HOST=$1; shift
ssh -F ${SSH_INFO} ${HOST} "sudo su - tungsten -c 'trepctl status'" | cut -d: -f2 > ${TMP_DIR}/${SCRIPT_NAME}.$$.${HOST}
done
# Quick paste of output
# NOTE: This does not handle reordered or missing rows of output
paste -d"\t" ${TMP_DIR}/${SCRIPT_NAME}.$$.*
rm -f ${TMP_DIR}/${SCRIPT_NAME}.$$.* ${TMP_DIR}/${SCRIPT_NAME}."hosts".$$
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment