명령 출력에서 ​​예외가 발생할 수 있는 조건을 생성하려면 어떻게 해야 합니까?

명령 출력에서 ​​예외가 발생할 수 있는 조건을 생성하려면 어떻게 해야 합니까?

aws cloudformation"DELETE_IN_PROGRESS" 또는 "ROLLBACK_IN_PROGRESS" 등의 텍스트 형식으로 스택 상태를 반환하는 명령을 받았습니다 .

aws cloudformation --region "$AWS_DEFAULT_REGION" describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[*].StackStatus' --output text

프로세스가 진행 중인 경우에만 스택 상태를 반환하고, 그렇지 않으면 다음 오류가 발생합니다.

An error occurred (ValidationError) when calling the DescribeStacks operation: Stack with id `foobar` does not exist

그래서 내 생각은 이러한 예외의 오류 메시지를 숨기고 텍스트 출력을 계산하는 것이었으므로 다음과 같이 했습니다.

AWS_DEFAULT_REGION='us-east-1'
STACK_NAME='blog-review-ci'

until test "$(aws cloudformation --region "$AWS_DEFAULT_REGION" describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[*].StackStatus' --output text 2>/dev/null)" = 'DELETE_IN_PROGRESS'; do
  echo "DELETE_IN_PROGRESS for $STACK_NAME, wait...";
  sleep 3s;
done

불행히도 이 문제는 계속해서 발생합니다.

DELETE_IN_PROGRESS for foobar, wait...

현재 DELETE_IN_PROGRESS가 발생하지 않아 통과 이유를 알 수 없으므로 이것은 잘못된 것입니다.

오류 발생 시 출력이 stderr/stdout인지 확인하기 위해 AWS 명령에 대한 자세한 정보를 찾으려고 하는데 해당 정보를 찾는 방법을 모르겠습니다.

또한 | grep 'DELETE_IN_PROGRESS' 명령을 실행해 보았지만 작동하지 않았습니다.

until aws cloudformation --region "$AWS_DEFAULT_REGION" describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[*].StackStatus' --output text | grep 'DELETE_IN_PROGRESS'; do
  echo "DELETE_IN_PROGRESS for $STACK_NAME, wait...";
  sleep 3s;
done

그 결과는 다음과 같습니다.

An error occurred (ValidationError) when calling the DescribeStacks operation: Stack with id blog-review-ci does not exist
DELETE_IN_PROGRESS for foobar, wait...

답변1

until분명히 필요한 곳에 사용하신 것 같아요 while.

whileuntilBash의 차이점.

관련 정보