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.
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerConvert that nightly cron job to a systemd timer. Why would you?IntermediateA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?Beginner