Scripts that do not cause incidents.
WHAT TO DO BEFORE ANY DESTRUCTIVE ACTION
Check that the variables hold what you expect.
WHY
An empty variable in a deletion path deletes far more than intended.
WHAT TO ADD
A dry-run mode that prints instead of acting.
WHY
It is the cheapest protection available, and it is used constantly.
WHAT TO VALIDATE
Every input Every path That required commands exist
WHAT TO NEVER ASSUME
That a directory exists That a command succeeded That the working directory is what you expect
WHAT TO USE INSTEAD
Absolute paths, and explicit checks.
WHAT LOGGING TO ADD
What the script did, with timestamps.
WHY
A script that runs unattended is only as good as its record.
WHAT TO DO ABOUT CONCURRENT RUNS
Prevent them with a lock.
WHY
Two copies of a backup or migration script running together corrupt things.
WHAT TO HANDLE
Interruption, cleaning up temporary files.
WHAT TO TEST
Failure paths, by inducing them.
WHAT TO KEEP
Scripts in version control, not only on the server.
WHAT TO DOCUMENT
What it does, what it needs, and how to run it.