FindInstanceInProfile.sh 844 B

123456789101112131415161718192021222324252627282930313233
  1. #! /bin/bash
  2. #
  3. # Usage:
  4. # FindInstanceInAccount.sh <instanceid> <accountname>
  5. if [ $# -ne 2 ]; then
  6. echo Usage: $0 "<searchstring> <profile>"
  7. exit 1
  8. fi
  9. # TODO: Sanitize search string
  10. SEARCHSTRING=$1
  11. PROFILE=$2
  12. # Cool, grab regions dynamically
  13. REGIONS=$(aws ec2 describe-regions --profile $PROFILE --output text --query 'Regions[*].RegionName')
  14. for region in $REGIONS; do
  15. (
  16. # Search by instance ID:
  17. aws ec2 describe-instances --profile $PROFILE --region $region --instance-id $SEARCHSTRING &> /dev/null && \
  18. echo "$SEARCHSTRING is in $region under profile $PROFILE"
  19. # Search by Name:
  20. aws ec2 describe-instances --profile $PROFILE --region $region --filter "Name=tag:Name,Values=$SEARCHSTRING" &> /dev/null && \
  21. echo "$SEARCHSTRING is in $region under profile $PROFILE"
  22. ) &
  23. done 2> /dev/null
  24. wait