Linux script command-the recorder in the terminal

Source: Internet
Author: User
Tags linux script command

Linux script command-the recorder in the terminal

When you work on a terminal or console, you may want to record what you do on the terminal. These records can be used as historical materials to save what happened on the terminal. For example, if you and some Linux administrators manage the same machine at the same time, or you want someone to remotely log on to your server, you may record what happens on the terminal. To achieve this goal, you can use the script command.

Linux vmstat command details

Detailed description of vmstat display results in Linux

Vmstat for Linux monitoring tools

Linux vmstat commands

Linux vmstat monitors system load

What is a script?

Scirpt is a command that can generate a record and output it to the terminal. This is useful for those who want to actually record terminal sessions. This record can be saved and printed later.

How to Use

By default, we can start the scirpt command by entering a script in the terminal.

  1. Pungki @ dev-machine :~ $ Script
  2. Script started, file is typescript
  3. Pungki @ dev-machine :~ $

You can also specify the target file name to record the printed results.

  1. Pungki @ dev-machine :~ $ Script myfile

When you see the command prompt again, this means that the terminal prints the record to anything on the terminal.

You will see a file named myscript in the current directory. (LCTT ing. The original text here is incorrect. The record file name is myfile instead of the default typescript .)

Why should we use the script command?

As mentioned earlier, the main function of script commands is to record everything. The following two scenarios use this command.

When working with colleagues

When working with colleagues, we can use scripts to record your activities.

For example, we will use a print file named collaborate to print:

  1. $ Script collaborate

Then, after completing some tasks, if you need to send your work to another engineer, send the file to him. So when another engineer needs to review what he does, he just needs to open the file in a text editor.

If he wants to update the file (to add his work part), use the-a option.

  1. $ Script-a collaborate

Record what someone does on the terminal

You may allow your engineers or someone to remotely access your system. To ensure that your engineers are doing the right thing, you can record what they are doing on your system. To enable the script command to run automatically at login, we can add it to the shell environment configuration file. If you are using bash shell, add this line to Your bash environment configuration file.

  1. $ Vi ~ /. Profile
  2. # Run the script command to record everything
  3. # Use-q for quite and-a option to append the script
  4. #
  5. /Usr/bin/script-qa/usr/local/script/log_record_script

Save the settings. The next time he logs on to your system, the script command runs automatically and records the logs into/usr/local/script/log.RecordScript.

-The q option allows the scirpt command to run in silent mode. the logged-in user does not know that the script command has been run. The-a option will append the record to the file rather than erase the previous record.

If the-q option is not used, the user will receive a notification like the one in when logging in.

Exit record

To exit the logging activity, press Ctrl + D on the terminal or enter exit. Before exiting the script, you will find that the size of the recorded file is 0 Kb, and after exiting, the file size will change.

End

Script commands may be useful when you need to record or archive terminal activities. record files are stored as text files, so they can be easily opened in a text editor. As usual, we can enter man script or scirpt-h to display the Help Page and view more detailed usage.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.