Skip to content

Instantly share code, notes, and snippets.

@cleblond
Forked from dustincurrie/elb.sh
Created August 21, 2020 17:00
Show Gist options
  • Save cleblond/7816ec336786b90b249bba1c47ff1dce to your computer and use it in GitHub Desktop.
Save cleblond/7816ec336786b90b249bba1c47ff1dce 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