Automation and DevOps

Automating Repetitive IT Tasks With Scripts

Learn how to spot IT jobs worth automating, estimate whether a script will pay off, and start with a small, safe first project before building anything bigger.

On this page
  1. Why bother automating
  2. Spotting jobs worth automating
  3. Start by writing the steps down
  4. Start small
  5. Choosing a tool
  6. Building in safety
  7. Keep it maintainable
  8. When not to automate

Why bother automating

Most IT teams have jobs that are done again and again: creating accounts, clearing out old files, checking that services are running, collecting information for a report. Each one takes only a few minutes, so it never seems worth fixing. Added up over a year, though, those minutes become hours, and the manual versions have a second cost. People forget steps, skip checks when they are rushed and do the job slightly differently each time.

A script is simply a written list of instructions that a computer follows. Turning a manual job into a script gives you speed, but the more important benefit is consistency. The job runs the same way on Tuesday afternoon as it does on Friday evening, and anyone on the team can run it.

Spotting jobs worth automating

Not everything deserves a script. Some questions help sort the good candidates from the rest.

How often does it happen? A task done daily is a better candidate than one done once a year. A rare task may still be worth writing down, but a full script may not pay for itself.

How long does it take, and how many people do it? A ten-minute job done by five people each week is a larger cost than it looks.

Is it a fixed set of steps? Tasks with clear rules, such as “if the file is older than 90 days, move it,” suit automation well. Tasks that need judgment about each case, such as deciding how to respond to an unusual user request, usually do not.

Is it error-prone? Jobs with many fiddly steps, where a typo causes damage, benefit from having the steps captured once and tested.

What happens if it goes wrong? The higher the stakes, the more careful the testing needs to be. Deleting temporary files is low risk. Changing permissions across many accounts is not.

A rough rule of thumb is to compare the time the script will take to write and maintain with the time it will save. Remember to include maintenance, because scripts depend on the systems they touch, and those change. If the numbers are close, the consistency benefit may still tip the decision.

Start by writing the steps down

Before opening an editor, do the task by hand once and record every step, including the small ones, such as which window you open or which folder you check first. This written checklist is useful even if you never automate it, because it shows what the job actually involves.

Then look at each step and ask whether a computer can do it. Typically you will find that most steps can, a few need a decision from a person and one or two depend on something awkward, such as a program with no way to be controlled from a script. Automating most of the job and leaving the awkward part manual is a perfectly good result.

Start small

A common mistake is trying to automate an entire process in one go. A better approach is to build up in layers.

  1. Automate the reading first. A script that only gathers information, such as listing disk space on a group of servers, cannot damage anything. It is a safe way to learn.
  2. Add one action at a time. Once the reading part works, add a single change and test it on a harmless target.
  3. Keep a person in the loop. Early versions can print what they would do and ask for confirmation before doing it.
  4. Remove the confirmation only when you trust it. Many scripts are never fully hands-off, and that is fine.

A “dry run” mode, where the script reports what it would change without changing anything, is one of the most valuable features you can add. It lets you check the plan before committing to it.

Choosing a tool

The right tool depends on the systems involved. Shell scripting or batch files are natural for simple jobs on a single machine, which is why they are a common first step, and beginners often get comfortable with command line basics at the same time. A general-purpose language is often a better choice when a script needs to handle data, talk to other services or grow beyond a page of code, and Python basics are a common route for people moving in that direction. Scheduling features built into the operating system can then run a script at a set time, such as every night.

Whichever you choose, prefer something your teammates can read. A clever script that only its author understands becomes a liability when that person is away.

Building in safety

Automation makes it easy to make a mistake quickly and at scale. A few habits reduce the risk.

  • Test on a copy or a single system first. Never try a new script across everything on its first run.
  • Be careful with deletion and overwriting. Where possible, move files to a holding area instead of deleting them straight away.
  • Check before acting. Confirm that the folder, server name or account actually exists and matches what you expect.
  • Log what the script does. A simple record of what ran and what changed makes problems far easier to trace, much like reading system logs after a failure.
  • Use limited permissions. A script that only needs to read a folder should not run with administrator rights. This is the principle of least privilege applied to your own tools, and it applies to service accounts that run scheduled jobs.
  • Keep secrets out of the script. Passwords written directly into a script tend to get copied around. Use the secure storage options your environment provides.

Keep it maintainable

Once a script is in use, it needs a little care. Add a comment at the top explaining what it does, who owns it and what it assumes. Keep the script in a shared location with history, so that changes can be reviewed and undone. Document it somewhere your team can find, in the same way that a good knowledge base documents manual procedures.

Review scripts from time to time. Systems change, and a script that worked well for a year may quietly start to do the wrong thing after an update. If a script is no longer used, retire it rather than leaving it to confuse people.

When not to automate

Automation is not always the answer. If a process itself is confused, automating it just makes the confusion faster. Fix the process first. If a task is changing frequently, wait until it settles. If you only do it twice a year, a good written checklist may serve better than code.

The goal is not to automate as much as possible. It is to remove the dull, error-prone work so that people can spend time on the problems that need thought.

The complete guide to automation and devops

DevOps Explained in Plain Language
Read the guide

Keep exploring

Guides from other topics

All topics →