使用 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


首頁