Teza's tech notes

Scripts that are safe to run twice

2 June 2025 · 1 min read
#python#bash#automation

The best automation scripts are boring. You can run them twice and nothing bad happens.

When a script has to touch a lot of things, I follow the same rules every time:

  1. Dry run first. Every script has a mode that prints what it would do. I read that before anything real happens.
  2. Back up before changing. If a script edits a config, it saves the old one first. Undo should be one command.
  3. Make it re-runnable. Check before creating. If the thing already exists and looks right, skip it. A half-finished run can simply be run again.
  4. Go in stages. One target, then a few, then the rest. Check the results between stages.
  5. Run in parallel, but log everything. Speed is nice; knowing exactly what happened is better.

Python (with boto3) for anything with logic, Bash for glue, PowerShell when I'm on Windows. The language matters less than the habits.