使用 script 记录所执行的过程

Idea from Andrew Lee, thank you :)

相信很多人在写 Linux 教学笔记或是除错时,是先开启终端机程式,再一行一行 copy/paste,现在有更好的方法,就是使用 script 这只小巧的程式,可以把你所执行的过程完全忠实的完全记录下来,如此就可以方便使用里面的内容来做分析,以下为使用方法:

root # script
Script started, file is typescript
root # touch /misc/temp_file{1,2,3,4}-{a,b,c,d}
root # ls -l /misc/temp_file*
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file1-a
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file1-b
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file1-c
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file1-d
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file2-a
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file2-b
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file2-c
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file2-d
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file3-a
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file3-b
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file3-c
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file3-d
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file4-a
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file4-b
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file4-c
-rw-r--r-- 1 root root 0 4月 22 15:45 /misc/temp_file4-d
root# exit
Script done, file is typescript
root#

以上是我们所执行的过程,看好最上面有一个 "script" 指令,表示要开始记录,而最后的 "exit" 代表结束录制。最后会产生一个 typescript 的档案,里面就是所有的执行过程。

root # ls -l typescript
-rw-r--r-- 1 root root 1490 4月 22 15:46 typescript
root #

档案内容:

root # cat typescript
root # ls -l /misc/temp_file*
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file1-a
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file1-b
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file1-c
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file1-d
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file2-a
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file2-b
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file2-c
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file2-d
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file3-a
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file3-b
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file3-c
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file3-d
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file4-a
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file4-b
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file4-c
-rw-r--r-- 1 root root 0 4月 22 15:53 /misc/temp_file4-d
root # exit
exit

Script done on Sat Apr 22 15:53:51 2006
root #

04/22/2006


首页