Last active
May 29, 2023 04:49
-
-
Save quangnhut123/2473cfc4ea6f5fe6a11d1fc87fa28853 to your computer and use it in GitHub Desktop.
Disable RDS Auto Minor Version Upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export AWS_REGION=ap-northeast-1 | |
check_profile() { | |
local profile=$1 | |
local specific_text=$2 | |
# Check if the profile contains the specific text | |
if [[ $profile == *"$specific_text"* ]]; then | |
return 0 # The string is found | |
else | |
return 1 # The string is not found | |
fi | |
} | |
process_profile() { | |
local profile=$1 | |
local specific_text=$2 | |
if [[ $profile == *"$specific_text"* ]]; then | |
echo -e "\n\n========== Processing profile: $profile ==========" | |
export AWS_PROFILE=$profile | |
db_cluster_identifier=$(aws rds describe-db-clusters --query "DBClusters[0].DBClusterIdentifier" --output text 2>/dev/null) | |
if [[ -z "$db_cluster_identifier" ]]; then | |
echo "Failed to get db_cluster_identifier" | |
return | |
fi | |
result=$(aws rds modify-db-cluster --db-cluster-identifier $db_cluster_identifier --no-auto-minor-version-upgrade --apply-immediately --no-cli-pager 2>/dev/null) | |
if [[ -z "$result" ]]; then | |
echo "Failed to change no-auto-minor-version-upgrade" | |
return | |
else | |
echo "Successfully change no-auto-minor-version-upgrade" | |
fi | |
fi | |
} | |
specific_text="$2" # Input the specific text here | |
while IFS='' read -r line || [[ -n "$line" ]]; do | |
if [[ $line =~ ^\[(.*)\]$ ]]; then | |
if check_profile "${BASH_REMATCH[1]}" "$specific_text"; then | |
process_profile "${BASH_REMATCH[1]}" "$specific_text" | |
fi | |
fi | |
done < "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment