Interview Prep/Linux/Scheduling, automation and scripting

Ops asks for a script that waits until a remote service is up before continuing a deployment. How do you write it?

BeginnerScenarioScheduling, automation and scripting
Answer

Situation read → Retry loop with a timeout.

What I'd do →

for i in $(seq 1 30); do
  if curl -fsS -o /dev/null --max-time 3 http://10.0.1.20:8080/healthz; then
    echo "up after $i tries"; exit 0
  fi
  sleep 5
done
echo "service not ready after 150s" >&2; exit 1

Why → A bounded loop avoids hanging a pipeline forever and gives a clear failure.

Interview tip → timeout 150 bash -c 'until curl -fs ...; do sleep 5; done' is a compact alternative.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting