All jobs / DevOps / SRE / cloud / Linux
DevOps / SRE / cloud interview question · 1–3 years
A deploy script failed on step two (the build), carried on, and pushed an empty artifact to production.
What do you change in the script?
The strongest answer
Start it with `set -euo pipefail` so a failed command, an unset variable or a failed pipeline stage stops the script, and quote every variable expansion
Why it works
Exactly — -e stops on error, -u catches typos in variable names, pipefail stops a pipeline hiding a failure. It is the first line of every serious script.
What a good answer covers
- Fail fast: set -euo pipefail.
- Quote every expansion.
- Check exit codes you depend on.
- Never silence errors to look green.
Answers that fall short
- Close, but not the strongest: Add `|| exit 1` after the build command so at least that step is checked
That guards one line; the next unguarded step, unset variable or pipeline will do the same thing. - Weak: Rewrite it in Python; Bash cannot fail safely
Language is not the problem; the same script without error handling fails the same way in Python. - Red flag: Redirect stderr to /dev/null so the noise stops and add a final echo saying “deploy OK”
Silencing errors and printing OK is how an empty artifact reaches production while everyone believes it worked.
Who gets asked this
More Linux questions
- `df -h` says the root volume is 100% full. `du -sh /` adds up to less than half of that. What is going on…
- Load average is 40 on an eight-core VM, yet `top` shows CPU mostly idle and the app is crawling. What does…
- `./deploy.sh` says “Permission denied” and `ls -l` shows `-rw-r--r--`. What do you do?
- What do you check, and what was the likely mistake?
- Everyone SSHes as root with the same key. What do you change first?
- A service fails to start with “address already in use” on port 8080. How do you find out what holds it?
- A runbook installs a CLI on every server with `curl https://… | sudo bash`. What do you prefer, and why?