Skip to content

Instantly share code, notes, and snippets.

@pcting
Created March 30, 2011 21:05
Show Gist options
  • Save pcting/895304 to your computer and use it in GitHub Desktop.
Save pcting/895304 to your computer and use it in GitHub Desktop.
Generate CSSH commands from hostnames generated by elb-describe-instance-health
#!/bin/sh
LB_HEALTH=$(elb-describe-instance-health 'my-elb-name')
echo "$LB_HEALTH"
LB_NAME=$(echo "$LB_HEALTH" | awk 'BEGIN { ORS=" " } { print $2 }')
echo "$LB_NAME"
INST_CMD=$(echo "$LB_NAME" | awk '{ print "ec2-describe-instances " $0 }')
echo "$INST_CMD"
INST_HEALTH=$(eval "$INST_CMD")
echo "$INST_HEALTH"
INST_NAME=$(echo "$INST_HEALTH" | grep ^INSTANCE)
echo "$INST_NAME"
SSH_LOGINS=$(echo "$INST_NAME" | awk '{ print "ubuntu@" $4 }')
echo "$SSH_LOGINS"
CSSH_CMD=$(echo "$SSH_LOGINS" | awk 'BEGIN { ORS=" " } { print $1 }' | awk 'BEGIN { FS="\n" } { print "cssh " $1 }')
echo "$CSSH_CMD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment