Skip to content

Instantly share code, notes, and snippets.

@dustincurrie
Created August 18, 2011 06:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dustincurrie/1153466 to your computer and use it in GitHub Desktop.
Save dustincurrie/1153466 to your computer and use it in GitHub Desktop.
Run a command on all instances attached to an AWS ELB
#!/bin/bash
# Runs a command on all instances attached to a load balancer
# Elastic Load Balancer Tools from http://aws.amazon.com/developertools/2536
ELB=prod-axs-aeg
COMMAND='service varnish restart'
INSTANCES=$(elb-describe-instance-health $ELB | awk -F " " '{print $2}')
for INSTANCEID in ${INSTANCES} ; do
INSTANCEURL=$(ec2-describe-instances $INSTANCEID | egrep '^INSTANCE' | awk -F " " '{print $4}')
$SSH -l root $INSTANCEURL $COMMAND
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment