2011-06-14 111 views
1

我已經在shell中編寫了一個安裝腳本,用於執行xserver,network等各種配置的一些配置,然後安裝幾個RPM,這是沒有問題的。但我希望能夠記錄進入終端屏幕的所有內容。這是否可以在腳本中完成,因此如果最終用戶運行./Install.sh,它將執行所有操作(包括日誌記錄)。在運行各種安裝腳本時記錄終端

我已經嘗試使用「腳本」,但不能從Install.sh腳本本身中工作。

感謝

回答

1

只需使用:

script logfilename install.sh 

當install.sh完成來看,script結束 - 所以,你得到的一切登錄到logfilename

也許你可以把它兩階段,所以,你應該將當前install.sh重命名爲install-stage2.sh,你的install.sh將包含:

script ./install.log ./install-stage2.sh 

UPDATE從我man script

NAME 
    script -- make typescript of terminal session 

SYNOPSIS 
    script [-akq] [-t time] [file [command ...]] 

DESCRIPTION 
    The script utility makes a typescript of everything printed on your terminal. It is useful for students who need 
    a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out 
    later with lpr(1). 

    If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is 
    saved in the file typescript. 

    If the argument command is given, script will run the specified command with an optional argument vector instead 
    of an interactive shell. 
+0

嘗試了腳本log.log沒有運氣的Install.sh,它似乎根本沒有啓動腳本。 – Danny 2011-06-15 14:58:25

+0

奇怪 - 因爲從我的'man script' - 請參閱編輯 – jm666 2011-06-15 19:42:11