diff --git a/tests/scripts/remote_retry.sh b/tests/scripts/remote_retry.sh index 8d997629..aa44ef86 100755 --- a/tests/scripts/remote_retry.sh +++ b/tests/scripts/remote_retry.sh @@ -1,6 +1,6 @@ #!/bin/bash -set +e + SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source ${SCRIPT_DIR}/.definitions.sh @@ -39,6 +39,7 @@ source ${SCRIPT_DIR}/.definitions.sh INTERVAL=30 SECONDS_ELAPSED=0 +set +e # Function to handle timeout exit handle_timeout() { echo "SECONDS_ELAPSED $SECONDS_ELAPSED" @@ -56,17 +57,20 @@ while [ $SECONDS_ELAPSED -lt $AWS_SYSTEM_ONLINE_CHECK_TIMEOUT ]; do # Attempt to connect via SSH and ignore errors # ssh -o ConnectTimeout=4 -i ${private_key} ${instance_hostname} "exit" || status=$? + SSH_EXIT_CODE=0 echo "SHIVA1" - ssh -o ConnectTimeout=5 -i ${private_key} ${instance_hostname} "exit" >/dev/null 2>&1 - echo "SHIVA2" + ( + ssh -o ConnectTimeout=5 -i ${private_key} ${instance_hostname} "exit" + ) >/dev/null 2>&1 + SSH_EXIT_CODE=$? # Check if SSH command succeeded - if [ $? -eq 0 ]; then + if [ $SSH_EXIT_CODE -eq 0 ]; then echo "Successfully connected to ${instance_hostname}." trap - EXIT # Disable the timeout trap since the connection was successful exit 0 fi - + echo "SHIVA2" sleep $INTERVAL # If SSH fails, wait for the interval before retrying SECONDS_ELAPSED=$((SECONDS_ELAPSED + INTERVAL))