Skip to content

Instantly share code, notes, and snippets.

@bageljp
Created October 13, 2013 11:37
Show Gist options
  • Select an option

  • Save bageljp/6961243 to your computer and use it in GitHub Desktop.

Select an option

Save bageljp/6961243 to your computer and use it in GitHub Desktop.
pssh command in hosts
#!/bin/bash
func_usage() {
echo "Usage: `basename $0` {role} {command}"
return 0
}
if [ $# -lt 2 ]; then
func_usage
exit 1
fi
ROLE="$1"
HOSTFILE="hostfile_${ROLE}_`date +%Y%m%d%H%M%S`"
cat /etc/hosts | grep ${ROLE} | grep -v "127.0.0.1" | grep -v ^$ | awk '{print $NF}' > ${HOSTFILE} &&
pssh -x '-t -t' -h ${HOSTFILE} -i $2
rm -f ${HOSTFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment