Development and automation

Automating routine work: which company tasks to hand over to a script

How to find operations in your company that are worth automating and how to judge whether automation will pay off. Typical examples, from exports between systems to checks, and a small Python script.

Alexei Sergeev 3 min read

Every company has operations that employees do by hand every day or every week: export a report from one system and import it into another, reconcile two spreadsheets, send reminders, check that nothing is broken. Each one takes little time on its own. Together they eat up hours and regularly cause mistakes.

Signs of a task worth automating

  • It repeats on a schedule or for the same trigger. Every morning, every Monday, with every new order.
  • It follows clear rules. If the task can be described in a one-page instruction, it can most likely be described in code too.
  • The data is already digital. In a business system, a spreadsheet, email or an API.
  • Mistakes are expensive. A wrong figure on an invoice or a missed reminder.

Tasks that need a human decision every time, or whose rules keep changing, are usually not worth automating end to end; it is better to automate the preparation of data for the decision.

Typical examples

  • Integrations between systems. Website orders go into the business system and statuses come back, with no manual copying.
  • Reports. Data from several sources gathered into one spreadsheet or dashboard that updates itself.
  • Notifications. A message in the team chat when something important happens: a large order, an overdue task, a sync error.
  • Checks. Expiry of certificates, domains and licences, presence of fresh backups.
  • Accounts. Creating and disabling an employee's access across several services in one action.

How to judge whether automation pays off

A simple estimate: how much time per month the task takes now, what a mistake costs and how often it happens. On the other side: the cost of development and support. A script nobody maintains breaks at the first change in an export format.

That is why I always build in a run log, a failure notification and short documentation: what the script does, where it runs and what to do if an error message arrives.

Example: checking TLS certificate expiry

A small Python example: the script checks how many days are left before the certificates on the company's websites expire and reports if it is below a threshold. It can run once a day on a schedule and send its output by email or to a chat.

check_certs.py
import socket
import ssl
from datetime import datetime, timezone

DOMAINS = ["example.com", "cloud.example.com", "mail.example.com"]
WARN_DAYS = 21


def days_left(host: str, port: int = 443) -> int:
    context = ssl.create_default_context()
    with socket.create_connection((host, port), timeout=10) as sock:
        with context.wrap_socket(sock, server_hostname=host) as tls:
            not_after = tls.getpeercert()["notAfter"]
    expires = datetime.fromtimestamp(ssl.cert_time_to_seconds(not_after), tz=timezone.utc)
    return (expires - datetime.now(timezone.utc)).days


def main() -> int:
    problems = []
    for domain in DOMAINS:
        try:
            left = days_left(domain)
        except OSError as exc:
            problems.append(f"{domain}: check failed ({exc})")
            continue
        if left < WARN_DAYS:
            problems.append(f"{domain}: certificate expires in {left} days")
    for line in problems:
        print(line)
    return 1 if problems else 0


if __name__ == "__main__":
    raise SystemExit(main())

Exit code 1 on problems lets you plug the check into any scheduler or monitoring system. That is the principle of good automation: a small, clear tool that does one thing and reports loudly when something is wrong.

When you need a service, not a script

If several employees work with the automation and you need access rights, change history and a convenient interface, it is already an internal web service. I build such services in Python and Django: a staff dashboard, an API for integrations, background jobs. More in the Development and automation section.

Is there routine work eating your employees' time?

Describe the process: what is done by hand, in which systems and how often. I will tell you what can be automated and how.

Discuss your task

Alexei SergeevEngineer, IT infrastructure and DevOps

Read next

An internal web app instead of Excel: when spreadsheets stop coping

Signs that tracking work in shared spreadsheets has started slowing things down, how an internal service beats a spreadsheet, and why a first version in Django often takes less work than you would expect.

Office network segmentation on MikroTik: VLANs for staff, guests and servers

Why a flat network where every device sees every other one is the main source of trouble in a small office, and how to split it into VLANs on MikroTik with RouterOS 7: the layout, bridge configuration, firewall rules an…

Backup internet for the office: two ISPs and automatic failover on MikroTik

How to set up a second internet connection so the office switches to it automatically and back again when the main provider recovers. Recursive routing on MikroTik, reachability checks and the pitfalls.