When you work in a terminal or console, you may want to record everything done in the terminal. These records can be used as historical data, save all terminals happened. For example, you and a number of Linux administrators to manage the same machine, or you let someone remotely login to your server, you may want to record what happened in the end. To achieve this goal, you can use the script command.
What is the script
scirpt is a command, you can make a record output to record the terminal. For those who want a true record terminal sessions, this is very useful. The recording can be saved and later printed.
how to use
By default, we can enter the script in a terminal to start scirpt command.
pungki @ dev-machine: ~ $ script
Script started, file is typescript
pungki @ dev-machine: ~ $
You can also specify the destination file name to print the results record.
pungki @ dev-machine: ~ $ script myfile
When you see the command prompt again, this means that the terminal will record anything printed to the terminal.
You will see the current directory, there is a file named myscript. (LCTT Annotation, where the original is wrong. This specifies a log file named myfile, instead of the default typescript.)
Why do we use script commands
As already mentioned before, the main function is to record the script command all things. Here are two scenarios using this command.
And when working with colleagues
When colleagues work together, we can record your activities through the script.
For example, we'll use to print the file named collaborate to complete the print:
$ Script collaborate
Then, to complete some task, if you do you need to live send another engineer, then put the document issued to him. So when another engineer needs to review much of what he had to do to open the file with a text editor on the line.
If he wants to update the file (to increase his part of the work), you can use the -a option.
$ Script -a collaborate
Record someone's actions in the terminal
You may make your engineer or someone remote access to your system, make sure that your engineers are doing the right thing, you can record what he does on your system. Let the script command runs automatically when you log in, we can add it into the shell environment configuration file. If you are using the bash shell, add this line to your bash environment configuration file.
$ Vi ~ / .profile
# Run the script command to record everything
# Use -q for quite and -a option to append the script
/ Usr / bin / script -qa / usr / local / script / log_record_script
Then save. Next time he logs into your system, script commands will automatically run, and the log records into the / usr / local / script / logrecordscript.
-q option allows scirpt command runs in silent mode, logged in users will not know the script command has been run. The -a option will allow records appended to the file, without erasing the previous record.
If you do not use the -q option, then when the user logs in, he will be notified like the figure below.
To exit record activity, we can press Ctrl + D in the terminal, or enter exit. Before exiting the script, you'll find the recording file size is 0 Kb, and after exiting, the file size will change.
Script commands you need to record or archive terminal activity may be useful when recording files are stored as a text file, so it can be easily opened with a text editor. As usual, we can enter man script or scirpt -h to display a help page and see more detailed usage.