mirror of
https://github.com/beyondx/Notes.git
synced 2026-02-04 10:54:00 +08:00
Add New Notes
This commit is contained in:
63
Zim/Utils/script/Using_script.txt
Normal file
63
Zim/Utils/script/Using_script.txt
Normal file
@@ -0,0 +1,63 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2011-11-28T11:31:15+08:00
|
||||
|
||||
====== Using script ======
|
||||
Created Monday 28 November 2011
|
||||
http://www.linuxhowtos.org/Tips%20and%20Tricks/using_script.htm
|
||||
|
||||
This tip shows you how to use script as a way to store or share __everything printed __during a terminal session. This can be a great way to remotely demonstrate command-line Linux to a less experienced user. Alternatively, it's a good way to keep a record of everything you do (or did) for a specific session.
|
||||
|
||||
First we'll look at keeping a record of everything. The can be done by just issuing the command script. The output of your session will be written to a file named **typescript**. If you want to specify a file other than the default, use script file where file is the name of the file storing the session.
|
||||
|
||||
===== Code Listing 1: Creating a script session =====
|
||||
|
||||
% script
|
||||
Script started, file is typescript
|
||||
% uptime
|
||||
13:27:53 up 89 days, 3:50, 1 user, load average: 0.27, 0.35, 0.29
|
||||
% uname -srvmpio
|
||||
Linux 2.4.20-gentoo-r4 #1 SMP Fri May 9 08:54:35 EDT 2003 i686 Intel(R) Xeon(TM)
|
||||
CPU 2.00GHz GenuineIntel GNU/Linux
|
||||
% exit
|
||||
Script done, file is typescript
|
||||
|
||||
The session file can be reviewed later with a** pager **such as more, less, or cat.
|
||||
|
||||
===== Code Listing 2: Viewing a script session =====
|
||||
|
||||
% more typescript
|
||||
Script started on Wed Aug 6 13:27:47 2003
|
||||
% uptime
|
||||
13:27:53 up 89 days, 3:50, 1 user, load average: 0.27, 0.35, 0.29
|
||||
% uname -srvmpio
|
||||
Linux 2.4.20-gentoo-r4 #1 SMP Fri May 9 08:54:35 EDT 2003 i686 Intel(R) Xeon(TM)
|
||||
CPU 2.00GHz GenuineIntel GNU/Linux
|
||||
% exit
|
||||
|
||||
Script done on Wed Aug 6 13:28:01 2003
|
||||
|
||||
Now we'll look at__ sharing a terminal session__. The easiest way to do this is combining script with mkfifo (which creates a **named pipe**). Note that you need to use the __-f__ option (script -f) to flush output after** each write**. This way, the terminal can be written to by User A and viewed in (near) real time by User B.
|
||||
|
||||
Code Listing 3: User A's terminal
|
||||
|
||||
% mkfifo demo; script -f demo
|
||||
Script started, file is demo
|
||||
% echo 'Hello World'
|
||||
Hello World
|
||||
% exit
|
||||
Script done, file is demo
|
||||
|
||||
|
||||
|
||||
Note: User A's terminal will __wait for input until User B issues the cat command__ (or accesses the named pipe).
|
||||
|
||||
Code Listing 4: User B's terminal
|
||||
|
||||
% cat demo
|
||||
Script started on Wed Aug 6 13:48:51 2003
|
||||
% echo 'Hello World'
|
||||
Hello World
|
||||
% exit
|
||||
|
||||
Script done on Wed Aug 6 13:49:04 2003
|
||||
41
Zim/Utils/script/amazing_Script.txt
Normal file
41
Zim/Utils/script/amazing_Script.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2011-11-28T11:33:53+08:00
|
||||
|
||||
====== amazing Script ======
|
||||
Created Monday 28 November 2011
|
||||
http://linux.byexamples.com/archives/279/record-the-terminal-session-and-replay-later/
|
||||
|
||||
I have read this at linuxinsight, which is amazing. You can actually record down your typing, screen output even you are running __ncurses cli__, all the **data** will store into a file and the **timing** will be into another file. With this two files, you can have__ scriptreplay__ to replay it all with the correct timing.
|
||||
|
||||
===== Recording goes like this =====
|
||||
|
||||
//script -t 2> tutorial.timing -a tutorial.session//
|
||||
|
||||
type ‘exit’ to end the recording.
|
||||
|
||||
===== Replay goes like this =====
|
||||
|
||||
//scriptreplay tutorial.timing tutorial.session//
|
||||
|
||||
Both session and timing file is readable, if you do not need to be replay, just do
|
||||
|
||||
//script -a tutorial.txt//
|
||||
|
||||
You might be asking what have script did? logged your input as well as screen output? That means the password will be recorded as well when you do sudo? The answer is NO, script save __only the things that is visible to you__, not your keyboard hit. Same things goes to scriptreplay, it just play what ever is recorded, __no real command executing during replay__.
|
||||
|
||||
I found that generating and replay with two files (session and timing files) is a bit messy. Therefore I created a bash script to cater that, I name it as script.sh. it will be creating only one file (it is just a dirty trick, read the bash script you will understand), replay and record uses script.sh is convenience.
|
||||
|
||||
To record,
|
||||
|
||||
./script.sh -r
|
||||
|
||||
To play,
|
||||
|
||||
./script.sh -p
|
||||
|
||||
Get script.sh and try it out. Remember to chmod +x after extract from the tar ball.
|
||||
|
||||
Oh ya, I included my output file here – matrix, download it and try to play with script.sh.
|
||||
|
||||
./script.sh -p matrix
|
||||
51
Zim/Utils/script/使用script记录Linux终端会话.txt
Normal file
51
Zim/Utils/script/使用script记录Linux终端会话.txt
Normal file
@@ -0,0 +1,51 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2011-11-28T11:09:42+08:00
|
||||
|
||||
====== 使用script记录Linux终端会话 ======
|
||||
Created Monday 28 November 2011
|
||||
http://hi.baidu.com/sdusoul/blog/item/c731833d7d8f19e53d6d9794.html
|
||||
|
||||
许多系统管理员都知道保留一个包含各种任务、配置改变等__活动日志__的重要性。对一些组织而言,保留“我做了这件事”或“约翰做了那件事”的简单日志就已足够;但另一些组织则需要记录所有改变。
|
||||
|
||||
对终端输出进行复制粘贴可能非常乏味,我们使用一个叫做script的鲜为人知的程序来解决这个问题,它是大多数Linux产品util-linux软件包的一部分。
|
||||
|
||||
script记录会话的一切内容:**你输入的内容和你看到的内容**。它甚至**记录颜色**;因此如果你的命令提示符或程序输出中包含颜色,script将记录它。
|
||||
|
||||
要使用script,简单执行以下命令:
|
||||
|
||||
$ script
|
||||
|
||||
默认情况下,它向当前目录的typescript文件中写入内容。然后,你输入的一切内容都被记录到那个文件中。要往另一个文件中记录日志,只需使用script/path/to/file命令。
|
||||
|
||||
完成记录后,输入exit退出。这个命令将关闭script会话并保存文件。现在你可以使用cat或其它任何程序来检查日志文件。
|
||||
|
||||
在ubuntu/或者其他linux下运行,script screen.log,记录屏幕信息到screen.log里,一直记录到你exit为止,记录屏幕log的好方法…
|
||||
|
||||
root@ubuntu2:/# script screen.log
|
||||
Script started, file is screen.log
|
||||
root@ubuntu2:/# ls -ltr
|
||||
total 76
|
||||
省略若干行>>>>>>>>>>>>>>>
|
||||
root@ubuntu2:/# exit
|
||||
exit
|
||||
Script done, file is screen.log
|
||||
root@ubuntu2:/# **cat screen.log**
|
||||
Script started on Wed Sep 24 21:34:52 2008
|
||||
root@ubuntu2:/# ls -ltr
|
||||
total 76
|
||||
省略若干行>>>>>>>>>>>>>>>
|
||||
root@ubuntu2:/# exit
|
||||
exit
|
||||
|
||||
Script done on Wed Sep 24 21:35:04 2008
|
||||
|
||||
已经找到了解决方法,异常退出也没有问题,仍然记录log,需要加上参数,script -f ido.log,如果在一个终端上使用**mkfifo ido.log;script -f ido.log **然后在另一个终端登录,找到这个ido.log文件,你__tail -f __就会滚动输出你操作的内容..这个非常方便…
|
||||
|
||||
2.使用script的缺点在于,它记录所有特殊的字符;因此你输入的文件中**将充满控制字符和ANSI转义序列**。你可以在script中使用一个非常简单的shell来解决这个问题:
|
||||
|
||||
SHELL=/bin/bash PS1=”$ ” script
|
||||
|
||||
使用script时,不要使用交互式程序或处理窗口的程序,如vior top。它们会破坏会话的输出结果。另外,日志文件会记录你使用的任何命令行程序和你完成一项任务所采取的步骤。如果你需要在脚本中编辑一个文件,考虑退出script会话,然后用script –a(它在旧会话后添加新会话)对文件进行编辑后再重新启动会话。
|
||||
|
||||
播放是不依赖于系统命令的,只要是一个支持ANSI控制码的终端就能再现;要求播放终端的大小和录制终端的大小一致,否则可能会出现显示偏差;显示的内容完全存放在demo.session中,辅以demo.timing中的时刻和控制操作来在屏幕显示;甚至可以录制vim的编辑过程,在没有(或者配置不同的)vim的机器上也能完美再现编辑操作的过程;多好的命令啊。。。
|
||||
Reference in New Issue
Block a user