Skip to content

Instantly share code, notes, and snippets.

@yeukhon
Created May 28, 2019 17:03
Show Gist options
  • Select an option

  • Save yeukhon/b3f0e651e07997d0671e44f95f436679 to your computer and use it in GitHub Desktop.

Select an option

Save yeukhon/b3f0e651e07997d0671e44f95f436679 to your computer and use it in GitHub Desktop.

Revisions

  1. yeukhon renamed this gist May 28, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. yeukhon created this gist May 28, 2019.
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/bash
    # This script takes two arguments: rds database identifier and timeout.

    DB_ID=$1
    TIMEOUT=$2
    POLL_INTERVAL=60
    OK_STATES=("backing-up" "available" "modifying" "resetting-master-credentials")

    seconds_left=$TIMEOUT

    while [[ "${seconds_left}" -gt 0 ]]
    do
    db_status=$(aws rds describe-db-instances --db-instance-identifier $DB_ID --query 'DBInstances[0].[DBInstanceStatus]' --output text)
    if [[ "${OK_STATES[@]} " =~ "${db_status}" ]]; then
    sleep 120
    exit 0
    else
    seconds_left="$((${seconds_left} - ${POLL_INTERVAL}))"
    sleep ${POLL_INTERVAL}
    fi
    done

    # Time exceeded here
    exit 1