Skip to content

Instantly share code, notes, and snippets.

@DylanGraham
Created February 29, 2016 03:29
Show Gist options
  • Save DylanGraham/6c7cb8273ae58aad8736 to your computer and use it in GitHub Desktop.
Save DylanGraham/6c7cb8273ae58aad8736 to your computer and use it in GitHub Desktop.
#!/bin/bash
fail() {
echo "Failed: $1"
exit 1
}
NODES=$(ssh mgt "diagnose -n | egrep '^comp[0-1][0-9][0-9].*Idle' | awk {'print \$1'}")
WORDS=$(echo ${NODES} | wc -w)
let "NUM_OF_NODES = $WORDS - 1"
NODES=$(echo $NODES | tr ' ' ',')
if [[ $? -ne 0 ]]; then
fail "Query mgt for idle nodes"
fi
echo -e "About to shutdown $NUM_OF_NODES nodes:\n "
echo "${NODES}"
echo
read -p "Are you sure? " -n 1 -r
echo
if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
xdsh ${NODES} 'shutdown -h now'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment