script command will record all keystrokes typed in a shell session to a file. Maybe you know about that, but if you’re using script to help with training, there’s some extra functionality that may be helpful.
script command itself. This can be useful when running a long sequence of commands by hand; for example, when carrying out a system upgrade, you may have a set of steps to follow. By using script to record all the keystrokes, in the event that there are problems you have an effective audit log of what was typed:
$ script upgrade_system.script
Now, all commands typed, together with the system prompt, will be recorded in
Tip: because script also records the shell prompt, if your prompt contains escape characters, they too will be written to the file.
You may want to start your script recording as follows:
FancyPrompt $ screen upgrade_system.script
FancyPrompt $ export PS1="$ "
That will reset your prompt just for the duration that you are recording the keystrokes.
To stop recording:
Script done, file is upgrade_system.script
If you’re recording keystrokes for future use as a training aid, this may be helpful:
$ script --timing=demo.timing demo.script
If you now run some commands and end with
exit, the commands can be replayed with the same timing as follows:
$ scriptreplay -t demo.timing -s demo.script
The rate of playback can be changed; see the
scriptreplay(1) man page.
Was this tip helpful?
Let us know in the comments below.