运行安装脚本时记录终端

时间:2011-06-14 20:57:08

标签: shell logging

我在shell中编写了一个安装脚本,它可以对xserver,网络等各种东西进行一些配置,然后安装几个RPM,这没问题。但我希望能够记录到终端屏幕的所有内容。这是否可以在脚本中执行,因此如果最终用户运行./Install.sh,它将执行所有操作(包括日志记录)。

我尝试过使用“脚本”,但在Install.sh脚本本身内无效。

由于

1 个答案:

答案 0 :(得分:1)

只需使用:

script logfilename install.sh

当install.sh完成运行时,script也会结束 - 所以,您将所有内容都记录到logfilename

您可以将其设为两个阶段,因此,您应该将当前install.sh重命名为install-stage2.sh,并且您的install.sh将包含:

script ./install.log ./install-stage2.sh
来自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.