Shell scripting & Python for DevOps
Bash for glue, Python for anything over 50 lines: argument parsing, error handling, calling APIs. If you do it twice, script it.
The mental model
Think of your automation toolbox as a kitchen. Bash is the countertop: it exists to move things between other tools — pipe the output of one program into another, loop over files, check an exit code, glue five binaries into one command. It is unbeatable for that and terrible at everything else. Python is the stand mixer: you reach for it the moment there is structure — JSON to parse, an API to page through, retries with backoff, arguments to validate, errors to report properly.
The dividing line most teams converge on is about 50 lines, or the first time you need any of: a data structure more complicated than a list of strings, JSON manipulation, HTTP calls with error handling, or unit tests. Below that line Bash is faster to write and read. Above it, Bash becomes a pile of awk and sed that nobody dares modify, and every edge case (a filename with a space, an empty result set, a network blip) turns into a production surprise.
The third rule matters more than either: if you do it twice, script it; if you script it, put it in the repo. A command that lives only in one engineer's shell history is not automation — it is a single point of failure with a person attached.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision