The art of doing nothing

In today’s fast-paced world, automation is key to saving time and increasing productivity. However, many people are hesitant to dive into automation headfirst due to concerns about the complexity of creating scripts and the potential for errors. This is where the concept of “do-nothing” scripting comes in. In this blog post, we’ll discuss what “do-nothing” scripts are and how they can be used to facilitate gradual automation. We’ll also provide three examples of “do-nothing” scripts written in bash scripting, Python, and Rust.

What Are “Do-Nothing” Scripts?

In essence, a “do-nothing” script is a script that does nothing. Rather than executing a set of instructions or performing a task, it simply runs and terminates. So why would someone create a script that doesn’t actually do anything? The answer lies in the idea of gradual automation.

Gradual automation is the process of automating tasks bit by bit, rather than all at once. This approach allows for greater control and customization of the automation process, as well as the ability to identify and resolve potential issues early on. “Do-nothing” scripts can be used to facilitate gradual automation by providing a starting point for more complex scripts. They allow users to test their scripts in a controlled environment, without having to worry about potentially harmful effects on their system.

Benefits of “Do-Nothing” Scripts

There are several benefits to using “do-nothing” scripts for gradual automation. These include:

  1. Simplicity: “Do-nothing” scripts are simple to create and execute, making them an excellent starting point for automation beginners.
  2. Testing: By creating a “do-nothing” script as a starting point, users can test their scripts in a controlled environment, identifying and resolving any issues before the script is put into production.
  3. Customization: “Do-nothing” scripts can be easily customized to fit a variety of automation needs, making them a versatile tool for gradually automating tasks.

Let’s see a few examples, in different languages, to run a simple task: Backup a PostgreSQL DB and upload the backtup to a GCS bucket.

#!/bin/bash

# This is a do-nothing script in bash to create a PostgreSQL backup and upload it to GCP buckets

# Step 1: Set the current date and time as a variable
echo "Step 1: Set the current date and time as a variable"
echo "To set the current date and time as a variable, run:"
echo ""
echo "  current_date=$(date +'%Y-%m-%d_%H:%M:%S')"
echo ""
read -p "Have you set the current date and time as a variable? Press enter to continue"

# Step 2: Backup PostgreSQL database to a file
echo "Step 2: Backup PostgreSQL database to a file"
echo "To backup PostgreSQL database to a file, run:"
echo ""
echo "  pg_dump dbname > backup_file.sql"
echo ""
read -p "Have you backed up the PostgreSQL database to a file? Press enter to continue"

# Step 3: Upload backup file to a Google Cloud Storage bucket
echo "Step 3: Upload backup file to a Google Cloud Storage bucket"
echo "To upload the backup file to a Google Cloud Storage bucket, run:"
echo ""
echo "  gsutil cp backup_file.sql gs://bucket-name"
echo ""
read -p "Have you uploaded the backup file to a Google Cloud Storage bucket? Press enter to continue"

The output of the do-nothing script above would be something like the following:

> ./script.sh
Step 1: Set the current date and time as a variableTo set the current date and
time as a variable, run:

    current_date=$(date +'%Y-%m-%d_%H:%M:%S')

Have you set the current date and time as a variable? Press enter to continue
Step 2: Backup PostgreSQL database to a fileTo backup PostgreSQL database to
a file, run:

    pg_dump dbname > backup_file.sql

Have you backed up the PostgreSQL database to a file? Press enter to continue
Step 3: Upload backup file to a Google Cloud Storage bucket
To upload the backup file to a Google Cloud Storage bucket, run:

    gsutil cp backup_file.sql gs://bucket-name

Have you uploaded the backup file to a Google Cloud Storage bucket? Press
enter to continue

And, just as an example, here’s a similar version but written in python:

#!/usr/bin/env python

import click

# This is a do-nothing script in Python using Click to create a PostgreSQL backup and upload it to GCP buckets

@click.command()
def main():
    # Step 1: Set the current date and time as a variable
    print("Step 1: Set the current date and time as a variable")
    print("To set the current date and time as a variable, run:\n")
    print("\tcurrent_date=$(date +'%Y-%m-%d_%H:%M:%S')\n")
    input("Have you set the current date and time as a variable? Press enter to continue")

    # Step 2: Backup PostgreSQL database to a file
    print("Step 2: Backup PostgreSQL database to a file")
    print("To backup PostgreSQL database to a file, run:\n")
    print("\tpg_dump dbname > backup_file.sql\n")
    input("Have you backed up the PostgreSQL database to a file? Press enter to continue")

    # Step 3: Upload backup file to a Google Cloud Storage bucket
    print("Step 3: Upload backup file to a Google Cloud Storage bucket")
    print("To upload the backup file to a Google Cloud Storage bucket, run:\n")
    print("\tgsutil cp backup_file.sql gs://bucket-name\n")
    input("Have you uploaded the backup file to a Google Cloud Storage bucket? Press enter to continue")

if __name__ == '__main__':
    main()

And the output is pretty similar:

> python test.pyStep 1: Set the current date and time as a variable
To set the current date and time as a variable, run:

        current_date=$(date +'%Y-%m-%d_%H:%M:%S')

Have you set the current date and time as a variable? Press enter to continue
Step 2: Backup PostgreSQL database to a file
To backup PostgreSQL database to a file, run:

        pg_dump dbname > backup_file.sql

Have you backed up the PostgreSQL database to a file? Press enter to continue
Step 3: Upload backup file to a Google Cloud Storage bucket
To upload the backup file to a Google Cloud Storage bucket, run:

        gsutil cp backup_file.sql gs://bucket-name

Have you uploaded the backup file to a Google Cloud Storage bucket? Press enter to continue

Conclusion

“Do-nothing” scripts may seem counterintuitive at first, but they can be an incredibly valuable tool for gradual automation. By starting with a simple script that does nothing, users can gradually build on that foundation to create more complex and powerful automation tools. Whether you’re just getting started with automation or you’re a seasoned pro, “do-nothing” scripts are a valuable addition to any automation toolkit.

Also, worth mentioning that the code exposed here is just for educational purposes which means it might now work properly (although I’m pretty sure it does). Anyway, the task is pretty simple to automate in a simple script.

References

Do-nothing scripting: the key to gradual automation