Automation vs Scripts
Why a script run by hand isn't automation: idempotency, declarative and imperative code, and what turns a script into automation.
Scripts are a start, not the finish
Most DBAs already write shell, PowerShell, or SQL scripts, and that's a great start. But a script that one person runs by hand isn't the same as automation. Real automation is versioned, reviewed, tested, safe to run repeatedly, logged, and runs at scale without someone watching it.
What turns a script into automation
| A typical script | Automation | |
|---|---|---|
| Where it lives | Someone's laptop or home directory | Git, reviewed through pull requests |
| How it runs | Someone starts it by hand | A schedule, a pipeline, an event, or a self-service request |
| Running it twice | Often breaks or does the work twice | Safe: it only changes what isn't already right (idempotent) |
| Describing the work | Every step, in order (imperative) | Often the end state wanted (declarative) |
| Targets | One server, typed in | An inventory of many servers, grouped by role and environment |
| Errors | May carry on after a failure | Stops, reports, and can roll back |
| Preview | None: it just runs | A dry run shows what would change first |
| Secrets | Passwords inside the script | Fetched from a vault at run time |
| Record | Whatever scrolled past on screen | Every run logged, with who, what, and when |
| Testing | Tried in production | Tested automatically on test systems first |
Idempotency: safe to run again
The single most important idea in automation is idempotency: running the same automation twice gives the same result as running it once. The first run makes the changes needed; later runs see that everything's already right and change nothing.
A typical script isn't idempotent. Run this twice and the second run fails, or worse, half-succeeds:
# create_user.sh: fails on the second run because the user already exists
sqlplus -s / as sysdba <<EOF
CREATE USER app_ro IDENTIFIED BY "Changeme1";
GRANT CREATE SESSION TO app_ro;
EOF
An automation tool checks first, and only acts if needed. In Ansible, the same task describes the desired state, and is safe to run any number of times:
# Ansible task: makes sure the user exists, and does nothing if it already does
- name: Ensure app_ro user exists
oracle_user:
schema: app_ro
schema_password: "{{ vault_app_ro_password }}"
grants: [create session]
state: present
Idempotency is what lets automation run on a schedule, or fix drift: if someone changes a server by hand, the next run quietly puts it back the way the code says it should be.
Imperative and declarative
- Imperative: how
- You write each step: "create the directory, then copy the file, then change the owner". Shell scripts and PowerShell are imperative. You're responsible for checking what's already there.
- Declarative: what
- You describe the end state: "this directory should exist, owned by oracle". The tool works out the steps, and does nothing if it's already true. Terraform is declarative, and most Ansible modules behave declaratively.
Declarative code is shorter, idempotent by nature, and easier to review, because it reads as a description of what should exist.
Scripts still matter
None of this makes scripting skills less useful. Automation tools run scripts all the time, and some tasks are easiest as a short script. The difference is how the script is treated: kept in Git, reviewed, made safe to rerun, run by a tool or pipeline rather than by hand, and logged. A good rule: if you've run it by hand three times, it's time to automate it properly.
Key takeaways
- A script run by hand from a laptop isn't automation; automation is versioned, reviewed, triggered, tested, logged, and runs at scale.
- Idempotency means running automation again changes nothing if everything's already right, which makes it safe to schedule and to fix drift.
- Imperative code lists steps; declarative code describes the end state and lets the tool work out the steps.
- Good automation previews changes, stops on errors, uses a vault for secrets, and is tested before production.
- Scripts still matter, inside automation; run something by hand three times, then automate it.