Python/Bash And Linux Operational Scripting
Asked of: Software Engineer
Last updated
What's being tested
Candidates must show practical mastery of Python and Bash scripting for operational tasks: parsing logs, automating workflows, and gluing system tools. Interviewers probe correctness, robustness (error handling, idempotency), and readable maintainable scripts you would check into a repo.
Patterns & templates
-
Shebang-led executable scripts — use
#!/usr/bin/env python3or#!/bin/bashand include usage/help flags for operability. -
Robust subprocess handling — prefer
subprocess.run(..., check=True)in Python; useset -eand||checks in bash for failures. -
Stream-processing with UNIX tools — combine
grep,awk,sed,cutand pipes for line-oriented transforms; avoid large in-memory buffers. -
Idempotent file ops — write to a temp file then
mvto target, use atomic renames to avoid partial-state races. -
Logging & exit codes — write structured logs, send errors to
stderr, return meaningful nonzero exit codes for orchestration. -
Scheduling & services — prefer
systemdtimers orcronfor simple periodic runs; ensure environment/PATHis explicit and use virtualenvs. -
Process control & signals — handle
SIGINT/SIGTERMin Python (signal), trap in bash to clean up temp files and child processes.
Common pitfalls
Pitfall: Assuming the runtime environment — scripts that rely on implicit
PATHentries or unstatedPYTHONPATHbreak in CI or cron.
Pitfall: Silent failures — swallowing exceptions or ignoring
stderrmakes debugging production incidents much harder than printing one clear error and exiting nonzero.
Pitfall: Memory-scaling mistakes — reading whole large log files into memory instead of streaming (
for line in file:) causes OOM on real-world datasets.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Related concepts
- Debugging, Observability, And Production OperationsSoftware Engineering Fundamentals
- Kubernetes, EKS, And Container Operations
- SQL/Python Data Manipulation And JoinsData Manipulation (SQL/Python)
- Python Data Manipulation And Core CodingCoding & Algorithms
- SQL And Python Data ManipulationData Manipulation (SQL/Python)
- Python/Pandas Data ManipulationData Manipulation (SQL/Python)