Wednesday, 14 June 2017

Write a bash script which remove all the ECS-Task Definition except the latest one

!/bin/bash rev_arry=$(aws ecs list-task-definitions --family-prefix <taskdef_name> --query taskDefinitionArns[]|cut -f7 -d :| cut -c1-2) maxrev_num=($rev_arry) arrlen=$((${#maxrev_num[@]}-2)) latest_revision=$(aws ecs list-task-definitions --family <taskdef_name> --sort desc --max-items 1 --query taskDefinitionArns|cut -c64-65) n="1" while [ $n -lt $arrlen ] do if [ ${maxrev_num[n]} -eq $latest_revision ]; then n=$[$n+1] fi delrevision=${maxrev_num[n]} aws ecs deregister-task-definition --task-definition <taskdef_name>:$delrevision echo "ecr taskdefiniton:$delrevision is deleted" n=$[$n+1] done

No comments:

Post a Comment