A fascinating thing about humans is that we each have a particular learning style. Some people prefer to read about how something's done. Some people prefer to follow instructions from the start, while others prefer to get an overview before engaging. Other people like to listen to instructions from an instructor or a podcast. And yet another group wants instructions in the form of a video.
The trouble with video is that it can be difficult to produce and compress, and it is a lot of work to change once it's done. And besides that, viewers can't copy and paste Linux commands out of a video into their terminal.
Or can they?
The script and scriptreplay commands allow you to record a terminal session and then play it back later. There's no video involved. Instead, plain text files called typescripts are used, so the files are small and users can copy commands during playback.
Both script and scriptreplay commands are valuable documentation tools, and I find them useful in two scenarios:
- No matter how sincerely I promise myself that I'll go through my shell history and gather the proper commands once I figure out the right way to accomplish a task, I rarely do.
- Sometimes, my users don't want to see the input required of them; they want to see the interaction between them and the computer. You can tell a user to type
lsand describe what they can expect to see in response, but it makes a greater impact when they see it happening themselves. I find users a lot braver in the terminal after playing a script file to see what it's like first.
[ Register for Ansible Basics: Automation Technical Overview and learn configuration management, provisioning, deploying, and managing compute infrastructure across environments with Ansible. ]
Record your terminal
To start recording with script, provide two destination files: a timing file and a typescript file:
$ script --timing=time.tm myscript
Output alerts you that script has started recording. Everything you do in your terminal while script is active is recorded. This includes everything going to stdin, stdout, and stderr, including your pauses, backspaces, auto-completions, and even your mistakes.
Press Ctrl+D or type exit to stop the recording when you've finished your demonstration.
The resulting typescript file, myscript in this example, is straightforward and relatively self-documenting:
Script started on 2022-01-06 22:27:01+13:00
0;seth:~/script^G$ echo "hello world"
hello world
0;seth:~/script^G$ exit
exit
Script done on 2022-01-06 22:27:10+13:00
You can edit this file. but beware of making too many changes because the output's timing has also been recorded.
Still, to correct minor errors, a quick edit with a text editor is an easy fix.
Playing a script
You can play a recorded script using the scriptreplay command:
$ scriptreplay --timing=time.tm myscript
This takes over your terminal session and uses it as a canvas to replay the input and output of what you recorded. The timing is replicated, too, so meaningful pauses for clarity are retained, which can be helpful to a user following along with the script playback.
Of course, the commands playing back in the terminal aren't being executed. It's just an instant replay, so it's safe to play scripts that delete files, make Git commits, or launch Ansible plays. Nothing in the playback of a script actually happens. It's just a movie.
Documentation in action
The script and scriptreplay commands are valuable tools for the "show don't tell" philosophy. Whether your target audience is you at some point in the future, long after you've forgotten what you were sure you'd never forget, or a timid new terminal user, seeing human-computer interaction can be illuminating and empowering.
Unlike screen captures, typescripts are small in file size and easy to update and edit. Unlike your shell history, typescripts aren't rotating. They don't go away unless you remove them yourself. And unlike shell scripts, a typescript demonstrates the steps without performing the process, encouraging the viewer to try each step, internalize it and commit it to memory, and gain a better understanding of what the terminal is truly capable of doing.
Über den Autor
Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).
Ähnliche Einträge
More than meets the eye: Behind the scenes of Red Hat Enterprise Linux 10 (Part 4)
Why should your organization standardize on Red Hat Enterprise Linux today?
What’s The Recipe For Burnout? | Compiler
The Sysadmin And The Script | Compiler: Re:Role
Nach Thema durchsuchen
Automatisierung
Das Neueste zum Thema IT-Automatisierung für Technologien, Teams und Umgebungen
Künstliche Intelligenz
Erfahren Sie das Neueste von den Plattformen, die es Kunden ermöglichen, KI-Workloads beliebig auszuführen
Open Hybrid Cloud
Erfahren Sie, wie wir eine flexiblere Zukunft mit Hybrid Clouds schaffen.
Sicherheit
Erfahren Sie, wie wir Risiken in verschiedenen Umgebungen und Technologien reduzieren
Edge Computing
Erfahren Sie das Neueste von den Plattformen, die die Operations am Edge vereinfachen
Infrastruktur
Erfahren Sie das Neueste von der weltweit führenden Linux-Plattform für Unternehmen
Anwendungen
Entdecken Sie unsere Lösungen für komplexe Herausforderungen bei Anwendungen
Virtualisierung
Erfahren Sie das Neueste über die Virtualisierung von Workloads in Cloud- oder On-Premise-Umgebungen