Interview Prep/Python for DevOps/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?

IntermediateScenarioAutomation scripting & CLI design
Answer

Situation read → Destructive script, unattended execution. Review for blast radius and safety.

What I'd do →

  1. Check the path is a constant or validated, never empty: a bug that turns the base into / or "" must abort.
  2. Check it uses Path.rglob with explicit patterns (*.log*) and skips symlinks (p.is_symlink()), so it cannot follow a link out of the directory.
  3. Confirm age uses st_mtime against timezone-consistent time.time().
  4. Require a --dry-run default or flag, log every deletion, and exit non-zero on errors.
  5. Catch PermissionError per file and continue, instead of aborting halfway.
  6. Ask whether logrotate already does this, which is usually the better answer.

Why → Cleanup scripts fail dangerously at their edges: empty variables, symlinks and permissions.

Interview tip → Mention logrotate or find -mtime +30 -delete; not every problem needs Python.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design