PrepPilotPractise free

Scripting & Automation interview questions

Bash, PowerShell, Python and jq for live exercises and fleet work

10 questions · #!/bin/bash · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What does set -euo pipefail do?

-e exits when a command fails, -u errors on unset variables, -o pipefail makes a pipeline fail if any command in it fails, not just the last. Together they stop scripts from blindly continuing after an error.

What does $? hold?

The exit code of the last command: 0 for success, non-zero for failure. Scripts and monitoring use it to decide what happened.

Single vs double quotes in bash?

Single quotes are literal: no variable or command expansion. Double quotes expand $var and $(cmd) but keep spaces intact. Use double quotes around variables almost always.

How do you pass arguments to a bash script?

$1, $2... for positional args, $@ for all of them (quoted: "$@"), $# for the count, and ${1:-default} for a default value.

Intermediate questions

Write a script that restarts a service if it isn't running.

if ! systemctl is-active --quiet nginx; then systemctl restart nginx; logger "nginx restarted by watchdog"; fi. Then mention that systemd's Restart=on-failure usually makes this unnecessary, and that you'd alert rather than silently restart forever.

How do you run a command on 100 servers?

Ansible ad-hoc or a playbook (ansible all -m shell -a 'cmd' -f 30) for Linux, Invoke-Command -ComputerName for Windows. A bash loop with ssh -o BatchMode=yes -o ConnectTimeout=5 works in a pinch. Always test on one host first, then a small batch.

PowerShell passes objects; bash passes text. Why does that matter?

In PowerShell you filter and select properties directly (Where-Object Status -eq 'Running') without parsing columns. In bash you parse text with awk/cut, which breaks if output format changes. Objects make scripts more reliable and easy to export (CSV, JSON).

How do you parse JSON in a shell script?

jq: e.g. jq -r '.items[].name'. For Azure CLI use --query with JMESPath and -o tsv for raw values. Don't grep JSON.

When do you use bash vs Python vs Ansible?

Bash for short glue around Linux commands. Python when there's logic, JSON/APIs, retries or it's growing past ~50 lines. Ansible when the job is 'make many servers look like this' and needs idempotency and inventory.

Senior questions

How do you make sure your automation can't take down production?

Idempotent checks before changes, a dry-run mode, strict error handling, timeouts, secrets from a vault, code review in Git, linting (shellcheck), and a staged rollout: one host, a canary group, then the rest, with a health check gate between stages and a documented rollback.

More Infrastructure Engineering topics