Skip to content

Instantly share code, notes, and snippets.

@skwp
Created October 26, 2018 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skwp/3c6f3c4cd1c95e5a1238e353382fe41c to your computer and use it in GitHub Desktop.
Save skwp/3c6f3c4cd1c95e5a1238e353382fe41c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#Find the ip addresses of running instances
# set -f disables file globbing so wthat we can invoke ./list-nodes test1 '*'
# otherwise the star is expanded and messes with the command
set -f
network_name=$1
role=$2
if [[ -z "$network_name" ]]; then
echo "Usage: list-nodes [network_name] [role]"
echo "Possible roles: client, miner, relay, or '*' (in single quotes) for all"
echo "Pass AWS_REGION=whatever to get specfic to a region: AWS_REGION=ap-southeast-1 ./list-nodes test1 '*'"
exit 1
fi
PROFILEFLAG=""
if [[ ! -z "$AWS_PROFILE" ]]; then
PROFILEFLAG="--profile=$AWS_PROFILE"
else
unset AWS_PROFILE
fi
aws ec2 describe-instances \
--query "Reservations[*].Instances[*].[Tags[?Key=='dns_name'].Value]" \
--filters "Name=tag:network_name,Values=${network_name}" "Name=instance-state-name,Values=running" "Name=tag:Name,Values=${role}" \
--region ${AWS_REGION:-"us-east-1"} \
--output=text $PROFILEFLAG
#!/usr/bin/env bash
# Execute arbitrary command on instances
# set -f disables file globbing so wthat we can invoke ./run-cmd test1 '*' 'command' to hit all nodes
# otherwise the star is expanded and messes with the command
set -f
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
network_name=$1
role=$2
command=$3
if [[ -z "$network_name" ]]; then
echo "Usage: run-cmd [network_name] [role:miner/client/relay/'*'] [cmd]"
echo "Example: run-cmd bx1 miner \"btcrpc getpeerinfo\""
echo "Please put the command in quotes if it has spaces"
exit 1
fi
# Finding us-east-1 nodes... use1_nodes=$(AWS_REGION=us-east-1 $DIR/list-nodes $network_name $role)
# Finding ap-southeast-1 nodes...
apse1_nodes=$(AWS_REGION=ap-southeast-1 $DIR/list-nodes $network_name $role)
if [[ ! -z "$use1_nodes" ]]; then
pssh -H "$use1_nodes" -x "-o LogLevel=quiet -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/mykey" -l ec2-user -i $command
fi
if [[ ! -z "$apse1_nodes" ]]; then
pssh -H "$apse1_nodes" -x "-o LogLevel=quiet -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/mykey" -l ec2-user -i $command
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment