Skip to content

Instantly share code, notes, and snippets.

@rokoroku
Created October 25, 2018 07:45
Show Gist options
  • Save rokoroku/74e7f5fe95a4dda604fda7a47b4fbfba to your computer and use it in GitHub Desktop.
Save rokoroku/74e7f5fe95a4dda604fda7a47b4fbfba to your computer and use it in GitHub Desktop.
AWS EC2 - open pssh / xpanes by application tag
TARGET_STAGE="prod"
TARGET_APPLICATION="bot-api"
KEYPAIR_PATH="~/.ssh/keypair.pem"
COMMANDS="pm2 logs all --lines 0"
TARGET_IP_ADDRS="$(aws ec2 describe-instances --filter Name=tag:Application,Values=${TARGET_APPLICATION} Name=tag:Stage,Values=${TARGET_STAGE} --query 'Reservations[].Instances[].[State.Name,InstanceId,PrivateIpAddress]' --output=text | grep running | awk '{print $3}' | tr '\n' ' ';)"
pssh -H "${TARGET_IP_ADDRS}" -x "-oStrictHostKeyChecking=no -i ${KEYPAIR_PATH}" -P "${COMMANDS}"
TARGET_STAGE="prod"
TARGET_APPLICATION="bot-api"
KEYPAIR_PATH="~/.ssh/keypair.pem"
TARGET_IP_ADDRS="$(aws ec2 describe-instances --filter Name=tag:Application,Values=${TARGET_APPLICATION} Name=tag:Stage,Values=${TARGET_STAGE} --query 'Reservations[].Instances[].[State.Name,InstanceId,PrivateIpAddress]' --output=text | grep running | awk '{print $3}' | tr '\n' ' ';)"
xpanes -t -s -c "ssh -o StrictHostKeyChecking=no {} -i ${KEYPAIR_PATH}" ${TARGET_IP_ADDRS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment