Merge pull request #1105 from GOLinux/master

Translated:20140530 Linux script command --A recorder inside your Terminal.md
This commit is contained in:
Xingyu.Wang 2014-06-01 23:16:59 +08:00
commit 169ebc0445
2 changed files with 83 additions and 86 deletions

View File

@ -1,86 +0,0 @@
Translating by GOLinux...
Linux script command - A recorder inside your Terminal
================================================================================
When you are working on the terminal or console, you may want to record what you have done in the terminal. The recording can be used as a documentation about what happen in terminal. Let say you are working together with some Linux Administrators at the same time. Or you let someone to remote your server. You may want to record about what happen in the terminal. To do this, you can use script command.
### What is script ###
script is a command that make a typescript that printed in the terminal. It is useful for everyone who need a hardcopy record of the session that happened in the terminal. This record can be saved and printed out later.
### How to use it ###
By default, we can start script with typing script on the terminal.
pungki@dev-machine:~$ script
Script started, file is typescript
pungki@dev-machine:~$
You can also define a destination filename to write the result of typescript.
pungki@dev-machine:~$ script myfile
![Define script file](http://linoxide.com/wp-content/uploads/2014/03/start_script.png)
When you received a command prompt again, it means the terminal will record anything that is printed in terminal.
You will see in the current directory, there is a file named typescript.
### Why we use script command ###
As we mention before, script has main function to record everything. Heres two samples of scenarios why we are using it.
#### Collaborate with colleague ####
When working together with your colleague, we can record your activity with script.
Let say we will use a typescript file called **collaborate**. To do that type :
$ script collaborate
![Create collaborate file](http://linoxide.com/wp-content/uploads/2014/03/collaborate.png)
Then after doing some tasks, let say you need to send your work to another engineer. Just send the file. So when the other engineer need to review what was done, he can just open the file using a text editor.
If he want to update the file, he can use **-a** option.
$ script -a collaborate
![Append the file](http://linoxide.com/wp-content/uploads/2014/03/collaborate_append.png)
#### Record someone activity in the terminal ####
You may let your engineer or someone to enter your system remotely. To make sure that your engineer are doing right, you can record what he had done to your system. To make the script command run automatically upon login, we can add it on your shell profile. If you are using **bash** shell, add this line into your bash profile.
$ 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
![Add script to bash profile](http://linoxide.com/wp-content/uploads/2014/03/script_login.png)
Then save it. Next time he logged in to your system, script command will automatically run and put the log on the **/usr/local/script/log_record_script**
![Script without notification](http://linoxide.com/wp-content/uploads/2014/03/remote_script_quite.png)
The option **-q** will run script command in quite mode. The user who logged in will not have any notification that the script command is run. While **-a** option will add the record without erasing the previous record.
If we dont use **-q** option, then when the user logged on, the user will get a notification about script as the picture below.
![Script with notification](http://linoxide.com/wp-content/uploads/2014/03/remote_script.png)
### Quit recording ###
To exit the record activity, we can press **Ctrl+D** button or type **exit** from the terminal. Before you exit from script, you will find the size of the record file is 0 Kb. After you exit from script, the file size will change.
### Conclusion ###
Script command may useful when you need to record or documenting what happen in the terminal. The record file will be stored as a text file, so it will easy to open it with any text editor. As usual, we can always type **man script** or **script -h** to display its manual page and explore it more detail.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/script-command-recorder/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -0,0 +1,83 @@
Linux script命令—— 终端里的记录器
================================================================================
当你在终端或者控制台工作时你可能想要记录在终端中所做的一切。这些记录可以用来当作史料保存终端所发生的一切。比如说你和一些Linux管理员们同时管理着相同的机器或者你让某人远程登陆到了你的服务器上你可能想要终端里发生的一切。要实现这个目标你可以使用script命令。
### script是什么 ###
scirpt就是一个命令可以把打字稿打印到终端。对于那些想要记录终端会话的硬拷贝的人来说这很有用。该记录可以保存并在以后再打印出来。
### 怎么用 ###
默认情况下我们可以通过在终端中输入script来启动scirpt命令。
pungki@dev-machine:~$ script
Script started, file is typescript
pungki@dev-machine:~$
你也可以指定目标文件名来记录打印结果。
pungki@dev-machine:~$ script myfile
![Define script file](http://linoxide.com/wp-content/uploads/2014/03/start_script.png)
当你再次见到命令提示符,这意味着终端将记录打印到终端的任何东西。
你会看到当前目录有个名为typescript的文件。
### 为什么我们要用script命令 ###
因为在之前已经提到过script命令的主要功能是记录所有的东西。下面给出了两个使用该命令的环境。
#### 和同事共事时 ####
当和同事一起工作时我们可以通过script来记录大家的活动。
比如,我们会使用名为**collaborate**的打印文件,来完成打印:
$ script collaborate
![Create collaborate file](http://linoxide.com/wp-content/uploads/2014/03/collaborate.png)
然后,在完成一些任务后,试想一下你需要把你干的活发给另外一个工程师,那就把那文件发给他。所以当另外一个工程师需要复查所做的事情,他只要用文本编辑器打开这个文件就行了。
如果他想要更新该文件,可以使用**-a**选项。
$ script -a collaborate
![Append the file](http://linoxide.com/wp-content/uploads/2014/03/collaborate_append.png)
#### 记录某人在终端中的所作所为 ####
你可能让你的工程师或者某个人远程访问你的系统要确保你的工程师正在干正确的事你可以记录下他在你系统上的所作所为。要让script命令在登录时自动运行我们可以把它添加进shell环境配置文件中。如果你正在使用**bash** shell把这一行加进你的bash环境配置文件中。
$ 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
![Add script to bash profile](http://linoxide.com/wp-content/uploads/2014/03/script_login.png)
然后保存。下次他登录进你的系统时script命令就会自动运行并把日志记录进**/usr/local/script/log_record_script**。
![Script without notification](http://linoxide.com/wp-content/uploads/2014/03/remote_script_quite.png)
**-q**选项可以让scirpt命令以静默模式运行登录进来的用户不会知道script命令已经运行了。而**-a**选项将会让记录附加到文件中,而不会擦除先前的记录。
如果不使用**-q**选项,那么当用户登录进来时,他会收到像下图中这样的通知。
![Script with notification](http://linoxide.com/wp-content/uploads/2014/03/remote_script.png)
### 退出记录 ###
要退出记录活动,我们可以在终端中按下**Ctrl+D**,或者输入**exit**。在退出script前你会发现记录文件的大小为0 Kb而在退出之后文件大小会发生改变。
### 结尾 ###
Script命令在你需要记录或者存档终端活动时可能很有用记录文件会存储为文本文件所以可以很方便地用文本编辑器打开。跟平常一样我们都可以通过输入**man script**或者**scirpt -h**来显示帮助页并查看更多详细用法。
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/script-command-recorder/
译者:[GOLinux](https://github.com/GOLinux) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出