I want to check if an application up and running by accessing the "health check" link, so I want to implement the following logic:
if it returns 200 the script stops working with exit code 0, but if it returns something else the script stops working with exit code 1, but I want to test the "health check" link 3 times in a row. So I did this
#!/bin/bash
n=0
until [ "$n" -ge 3 ]
do
    i=`curl -o /dev/null -Isw '%{http_code}\n' localhost:8080`
    if [ "$i" == "200" ]
    then
        echo "Health check is OK"
        break
    else
        echo "Health check failed"
    fi
    n=$((n+1))
    sleep 5
done
When it's 200 and break is triggered, it exits with exit code 0, which is fine, but I also want it to exit with exit code 1 if it's not 200 but after the third iteration of the until loop. If I add exit 1 inside or below the "if statement" the script exits with exit code 1 but after the first iteration.
Is there any way to make it exit with exit code 1 after the third iteration of the loop?
 
     
     
     
    