INTERVIEW PREP
Interview questions
570 questions from real DevOps, SRE, platform engineering and MLOps interviews, with the answer an interviewer wants to hear. Try answering out loud first, then open the model answer.
Showing 1–6 of 6 questions
Learn Bash Scripting →1.How do you prevent two copies of a cron script running at once?Senior
Use a lock: exec 9>/var/lock/job.lock; flock -n 9 || exit 0. The kernel releases the lock when the process exits, even if it crashes, unlike a hand-made PID file.
2.How do you test and lint Bash scripts in CI?Senior
Run ShellCheck on every script, write tests with bats-core, run with bash -n for syntax, and test under the shell that will run it (dash for /bin/sh scripts).
3.When should you stop using Bash and switch to Python?Senior
Switch when the script needs real data structures, JSON/YAML parsing, error handling with retries, unit tests, or grows past roughly 100-200 lines. Bash is great for gluing commands together; Python is easier to read, test and maintain for logic.
4.How do you run commands in parallel in Bash and wait for them?Senior
Start them with & and call wait; capture each PID to check exit codes (wait $pid). For many jobs, xargs -P 8 or GNU parallel limits how many run at once.
5.How do you make a script safe to run twice (idempotent)?Senior
Check state before changing it: mkdir -p, id user || useradd user, grep -q line file || echo line >> file. Use lock files (flock) to stop overlapping runs, and write to a temp file then mv it into place so a crash never leaves half a file.
6.How do you keep secrets out of shell scripts and logs?Senior
Read secrets from environment variables or a secret manager at runtime, never hardcode them. Avoid set -x around secret lines, don't pass secrets as command-line arguments (they show in ps), and use read -s for prompts.