securitybreach Posted September 19, 2015 Share Posted September 19, 2015 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/ 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.