Jump to content

How to Record and Replay Linux Terminal Sessions


securitybreach

Recommended Posts

securitybreach

In this guide we are going to look at how to use a script and scriptreplay commands in Linux that can help you to record commands and their output printed on your terminal during a given session.

 

The history command is a great command-line utility that helps users to store previous command used, though it does not store the output of a command.

 

Therefore the script command comes in handy to provide you a powerful functionality that helps you to record everything that is printed on your terminal to a log_file. You can then refer to this file later on in case you want to view the output of a command in history from the log_file.

 

You can also replay commands that you recorded using the scriptreplay command by using a timing information.

 

How to Record Linux Terminal Using script Command

 

The script command stores terminal activities in a log file that can be named by a user, when a name is not provided by a user, the default file name, typescript is used.

 

Basic Syntax of script Command

# script [options] - -timing=timing_file log_filename

 

To start recording of Linux terminal, type script and add the log filename as shown.

tecmint@tecmint ~ $ script history_log.txt

 

Script started, file is history_log.txt

 

To stop script, type exit and press [Enter].

tecmint@tecmint ~ $ exit

 

Script done, file is history_log.txt

 

If the script can not write to the named log file then it shows an error.

 

For example, in the output below, the permissions of the file typescript does not allow reading, writing and execution of the file not by any user or group. When you run the script command without a log file name, it attempts to write to the default file, typescript hence showing an error.

 

tecmint@tecmint ~ $ ls -l typescript

--------- 1 ubuntu ubuntu 144 Sep 15 00:00 typescript

 

tecmint@tecmint ~ $ script
script: open failed: typescript: Permission denied

............

 

http://www.tecmint.c...s-using-script/

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...