From 28b27b4e2c93909da548a40c48a20934a58fc72d Mon Sep 17 00:00:00 2001 From: Ashish Jullia Date: Fri, 25 Sep 2026 14:50:28 -0400 Subject: [PATCH] Show the MFA code prompt on the terminal. The prompt was written to stderr and then discarded, so startup looked frozen while it waited for the code. --- script.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/script.sh b/script.sh index eccfef0..5504cb9 100644 --- a/script.sh +++ b/script.sh @@ -61,11 +61,13 @@ EOF # AWS_MFA_SERIAL comes from this Portunus project. The one-time code does not. if [ -n "${AWS_MFA_SERIAL:-}" ]; then echo "MFA is required before assuming ${AWS_ROLE_TO_ASSUME}." - if ! read -r -s -p "MFA code: " mfa_code /dev/null; then - read -r -s -p "MFA code: " mfa_code || error_exit "AWS_MFA_SERIAL is set for this project, but there is no terminal to read an MFA code." - printf '\n' + # read -p writes the prompt to stderr. Discarding stderr hides it and looks like a hang. + if [ -r /dev/tty ] && [ -w /dev/tty ]; then + printf 'MFA code: ' >/dev/tty + IFS= read -r mfa_code /dev/tty + printf 'MFA code: ' >&2 + IFS= read -r mfa_code || error_exit "AWS_MFA_SERIAL is set for this project, but there is no terminal to read an MFA code." fi if [ -z "${mfa_code}" ]; then error_exit "An MFA code is required to assume ${AWS_ROLE_TO_ASSUME}."