Your team has a 300-line Bash script that parses JSON with `jq`, loops over AWS accounts and retries with `sleep`. It breaks every month. Do you rewrite it in Python?
BeginnerScenarioAutomation scripting & CLI design
Answer
Situation read → The script has outgrown Bash: data structures, API calls, retries and error handling are all things Bash does badly.
What I'd do →
- Write down what it actually does today (inputs, outputs, side effects, exit codes) and capture a sample run's output as a reference.
- Rewrite in Python with boto3, a click CLI, logging and built-in retries (
Config(retries={"mode": "adaptive"})), keeping the same flags and output so callers do not change. - Add pytest tests with moto for the core logic and compare output against the reference run.
- Ship it side by side for one cycle, then switch callers over.
Why → A behaviour-preserving rewrite with tests removes the monthly breakage without surprising the people who depend on it.
Interview tip → Say you keep the external contract identical; rewrites fail when they change behaviour and tooling at the same time.
More on Automation scripting & CLI design
A colleague's script deletes files older than 30 days from `/var/log/app`. You are asked to review it before it goes into cron. What do you look for?IntermediateYou need a script that ops engineers run from laptops and that CI runs nightly. How do you design its interface?IntermediateA script reads a 15 GB access log to count 5xx errors per endpoint, and the box runs out of memory. How do you fix it?BeginnerYou must run the same Python automation on 40 servers that have Python 3.6, 3.9 and 3.12. What do you do?IntermediateA cron job that runs a Python script fails silently. Nobody noticed for two weeks. How do you make sure that never happens again?IntermediateProduct wants a Slack notification whenever a deploy finishes. You have 30 minutes. What do you build?Beginner