在运行各种安装脚本时记录终端 [英] Logging terminal while running an install script of sorts
问题描述
我已经在shell中编写了一个安装脚本,该脚本对xserver,network等各种事物进行了一些配置,然后安装了一些RPM,这是没有问题的.但是我也希望能够记录到终端屏幕的所有内容.是否可以在脚本中执行此操作,因此如果最终用户运行./Install.sh,它将执行所有操作(包括日志记录).
我尝试使用脚本",但在Install.sh脚本本身中无法使用.
谢谢
只需使用:
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.
I have written an install script in shell that does some configuration of various things such as xserver, network, etc and then installs a few RPM's which is no problem. But I want to be able to log everything that goes to the terminal screen as well. Is this possible to do from within the script so if the end user runs ./Install.sh it will do everything (including the logging).
I have tried using "script" but doesn't work from within the Install.sh script itself.
Thanks
Just use:
script logfilename install.sh
when the install.sh finished the run, the script
end too - so, you get everything logged into logfilename
.
Probably you can make it two-stage, so, you should rename your current install.sh
into install-stage2.sh
and your install.sh will contain:
script ./install.log ./install-stage2.sh
UPDATE from my 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.
这篇关于在运行各种安装脚本时记录终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!