CLI Automation – Using the Command Line to Automate Repetitive Tasks – Mike Osolinski

09 April 2019

Posted in: BSEO

Overview

Mike Osolinski from Edit talked about CLI automation and how to use command line to automate repetitive tasks.

The main points covered off in his talk included:

  • Outlining what command line is and how it helps us to work more efficiently.
  • Offering a few examples using CLI scripts of how time and effort can be saved.
  • How multiple scripts can be chained together to create automation solutions.

What is command line and how does it help?

Command line is a language interpreter that allows a user to issue commands to their computer in the form of successive lines of text. You can open command line on your device by searching ‘command prompt’ if you’re on a PC or by opening Mac OS terminal on a Mac.

Mike did offer a warning, however, to suggest that you’ll need to be careful when writing scripts using command line, often things this way cannot be undone and you can do some serious damage to your machine if you don’t know what you’re doing.

While it’s quick and easy to write ad-hoc scripts you can also take advantage of a huge library of pre-built scripts. Mike also noted how you can then chain different scripts and libraries together to create fully automated solutions.

Examples of command line tasks

A few examples of basic tasks Mike covered included:

  • Merging files
  • Optimising images
  • Extracting data
  • Running Lighthouse reports
  • Running Screaming Frog reports
  • Renaming files
  • Manipulating CSV files

Merging files

Windows – copy *.csv > merged.csv
Linux/Mac – cat *.csv > merged.csv

Renaming files

Optimising images

Running Screaming Frog reports

Mike then went on to talk about PowerShell which is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

Using this language you can create cmdlet’s (pronounced command let) to perform a single function and automate processes.

For instance, the Imort-CSV cmdlet turns a CSV file into an object with properties that can easily be referenced with filters like:

  • it (less than)
  • gt (greater than)
  • eq (equal to)
  • like (like)

So you can then begin to automate tasks like pulling all page titles longer than X and pulling them into an audit document or adding bulk redirects into a CSV file to be uploaded.

Here’s the Import-CSV cmdlet for redirects:

Linking things together

In order to combine tasks, for instance, not just generating the list of redirects but actually creating those redirects, you will have to link two tasks together.

This is how Mike explains this is done:

&

Mike summarised by saying tasks like this are just the tip of the iceberg of what automation using command line is capable of before highlighting some useful resources for learning more about CLI scripting:

Share This
instagram logo

Seeker Digital

  • 22
  • 0
  • 17
  • 2
  • 14
  • 0
  • 13
  • 0
  • 21
  • 0