]> git.ipfire.org Git - thirdparty/util-linux.git/blame - term-utils/script.1
script: support multi-stream logging
[thirdparty/util-linux.git] / term-utils / script.1
CommitLineData
6dbe3af9
KZ
1.\" Copyright (c) 1980, 1990 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)script.1 6.5 (Berkeley) 7/27/91
33.\"
6e72fa59 34.TH SCRIPT "1" "June 2014" "util-linux" "User Commands"
c5e7b9fa
SK
35.SH NAME
36script \- make typescript of terminal session
37.SH SYNOPSIS
38.B script
6e72fa59
BS
39[options]
40.RI [ file ]
c5e7b9fa
SK
41.SH DESCRIPTION
42.B script
6e72fa59 43makes a typescript of everything displayed on your terminal. It is useful for
c5e7b9fa
SK
44students who need a hardcopy record of an interactive session as proof of an
45assignment, as the typescript file can be printed out later with
46.BR lpr (1).
c1c2ee0b
KZ
47Since version 2.35
48.B script
49supports multiple streams and allows to log input and output to separate
50files or all the one file.
c5e7b9fa 51.PP
6dbe3af9 52If the argument
c5e7b9fa 53.I file
ddbdb792 54or option \fB\-\-log\-out\fR \fIfile\fR is given,
c5e7b9fa 55.B script
6e72fa59 56saves the dialogue in this
c5e7b9fa 57.IR file .
6e72fa59
BS
58If no filename is given, the dialogue is saved in the file
59.BR typescript .
c5e7b9fa 60.SH OPTIONS
aefe9893
FM
61Below, the \fIsize\fR argument may be followed by the multiplicative
62suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB
63(the "iB" is optional, e.g. "K" has the same meaning as "KiB"), or the suffixes
64KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB.
c5e7b9fa
SK
65.TP
66\fB\-a\fR, \fB\-\-append\fR
6dbe3af9 67Append the output to
c5e7b9fa 68.I file
6e72fa59
BS
69or to
70.BR typescript ,
6dbe3af9 71retaining the prior contents.
c5e7b9fa
SK
72.TP
73\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR
73bc3206 74Run the
c5e7b9fa
SK
75.I command
76rather than an interactive shell. This makes it easy for a script to capture
77the output of a program that behaves differently when its stdout is not a
78tty.
79.TP
80\fB\-e\fR, \fB\-\-return\fR
73bc3206 81Return the exit code of the child process. Uses the same format as bash
6343ee8c
KZ
82termination on signal termination exit code is 128+n. The exit code of
83the child process is always stored in type script file too.
c5e7b9fa
SK
84.TP
85\fB\-f\fR, \fB\-\-flush\fR
86Flush output after each write. This is nice for telecooperation: one person
87does `mkfifo foo; script -f foo', and another can supervise real-time what is
88being done using `cat foo'.
89.TP
90\fB\-\-force\fR
91Allow the default output destination, i.e. the typescript file, to be a hard
92or symbolic link. The command will follow a symbolic link.
93.TP
c1c2ee0b
KZ
94\fB\-B\fR, \fB\-\-log\-io\fR \fIfile\fR
95Log input and output to the same
96\fIfile\fR. Note, this option makes sense only if \fB\-\-log\-timing\fR is
97also specified, otherwise it's impossible to separate output and input streams from
98the log \fIfile\fR.
99.TP
70062aad
KZ
100\fB\-I\fR, \fB\-\-log\-in\fR \fIfile\fR
101Log input to the \fIfile\fR. The log output is disabled if only \fB\-\-log\-in\fR
102specified.
103.sp
104Use this logging functionality carefully as it logs all input, including input
105when terminal has disabled echo flag (for example it log passwords in the input).
106.TP
ddbdb792 107\fB\-O\fR, \fB\-\-log\-out\fR \fIfile\fR
70062aad
KZ
108Log output to the \fIfile\fR. The default is to log output to the file with
109name 'typescript' if the option \fB\-\-log\-out\fR or \fB\-\-log\-in\fR is not
110given. The log output is disabled if only \fB\-\-log\-in\fR specified.
ddbdb792 111.TP
fc58044f 112\fB\-T\fR, \fB\-\-log\-timing\fR \fIfile\fR
c1c2ee0b
KZ
113Log timing information to the \fIfile\fR. Two timing file formats are supporte
114now. The classic format is used when only one stream (input or output) logging
115is enabled. The multi-stream format is used on \fB\-\-log\-io\fR or when
116\fB\-\-log\-in\fR and \fB\-\-log\-out\fR are used together.
fc58044f 117.sp
c1c2ee0b
KZ
118.RS
119.B Classic format
120.PP
121The log contains two fields, separated by a space. The first
fc58044f 122field indicates how much time elapsed since the previous output. The second
c1c2ee0b
KZ
123field indicates how many characters were output this time.
124.sp
125.B Multi-stream format
126.PP
127The first field is entry type itentifier ('I'nput, 'O'utput, 'H'eader, 'S'ignal).
128The socond field is how much time elapsed since the previous entry, and rest of the entry is type specific data.
129.RE
fc58044f 130.TP
aefe9893
FM
131\fB\-o\fR, \fB\-\-output-limit\fR \fIsize\fR
132Limit the size of the typescript and timing files to
133.I size
134and stop the child process after this size is exceeded. The calculated
135file size does not include the start and done messages that the
136.B script
137command prepends and appends to the child process output.
138Due to buffering, the resulting output file might be larger than the specified value.
139.TP
c5e7b9fa 140\fB\-q\fR, \fB\-\-quiet\fR
6f3c9c34 141Be quiet (do not write start and done messages to standard output).
c5e7b9fa 142.TP
3cf274c9 143\fB\-t\fR[\fIfile\fR], \fB\-\-timing\fR[=\fIfile\fR]
c5e7b9fa
SK
144Output timing data to standard error, or to
145.I file
fc58044f
KZ
146when given. This option is deprecated in favour of \fB\-\-log\-timing\fR where
147the \fIfile\fR argument is not optional.
c5e7b9fa
SK
148.TP
149\fB\-V\fR, \fB\-\-version\fR
b4362b6f 150Display version information and exit.
c5e7b9fa
SK
151.TP
152\fB\-h\fR, \fB\-\-help\fR
b4362b6f 153Display help text and exit.
c5e7b9fa 154.SH NOTES
6dbe3af9 155The script ends when the forked shell exits (a
c5e7b9fa 156.I control-D
6e72fa59 157for the Bourne shell
dbeb1d73 158.RB ( sh (1p)),
6dbe3af9 159and
c5e7b9fa
SK
160.IR exit ,
161.I logout
6dbe3af9 162or
c5e7b9fa 163.I control-d
6dbe3af9 164(if
c5e7b9fa 165.I ignoreeof
6dbe3af9
KZ
166is not set) for the
167C-shell,
c5e7b9fa
SK
168.BR csh (1)).
169.PP
6dbe3af9 170Certain interactive commands, such as
c5e7b9fa 171.BR vi (1),
6dbe3af9 172create garbage in the typescript file.
6e72fa59 173.B script
c5e7b9fa
SK
174works best with commands that do not manipulate the screen, the results are
175meant to emulate a hardcopy terminal.
8fd4a7aa
SB
176.PP
177It is not recommended to run
178.B script
c8a550a1 179in non-interactive shells. The inner shell of
8fd4a7aa 180.B script
c8a550a1 181is always interactive, and this could lead to unexpected results. If you use
8fd4a7aa 182.B script
ab52a8bc 183in the shell initialization file, you have to avoid entering an infinite
c8a550a1
BS
184loop. You can use for example the \fB\%.profile\fR file, which is read
185by login shells only:
8fd4a7aa
SB
186.RS
187.RE
188.sp
189.na
190.RS
191.nf
192if test -t 0 ; then
193 script
ab52a8bc 194 exit
8fd4a7aa
SB
195fi
196.fi
197.RE
c8a550a1 198.ad
8fd4a7aa 199.PP
ab52a8bc
SB
200You should also avoid use of script in command pipes, as
201.B script
202can read more input than you would expect.
203.PP
c5e7b9fa 204.SH ENVIRONMENT
6dbe3af9 205The following environment variable is utilized by
c5e7b9fa
SK
206.BR script :
207.TP
208.B SHELL
6dbe3af9 209If the variable
6e72fa59 210.B SHELL
6dbe3af9 211exists, the shell forked by
c5e7b9fa 212.B script
6e72fa59
BS
213will be that shell. If
214.B SHELL
c5e7b9fa
SK
215is not set, the Bourne shell is assumed. (Most shells set this variable
216automatically).
217.SH SEE ALSO
218.BR csh (1)
6dbe3af9 219(for the
c5e7b9fa 220.I history
ffc43748 221mechanism),
f053ff1e 222.BR scriptreplay (1)
c5e7b9fa 223.SH HISTORY
6dbe3af9 224The
c5e7b9fa
SK
225.B script
226command appeared in 3.0BSD.
227.SH BUGS
6e72fa59 228.B script
6dbe3af9 229places
6e72fa59 230.I everything
c5e7b9fa
SK
231in the log file, including linefeeds and backspaces. This is not what the
232naive user expects.
63ddc7ba
KZ
233.PP
234.B script
c8a550a1
BS
235is primarily designed for interactive terminal sessions. When stdin
236is not a terminal (for example: \fBecho foo | script\fR), then the session
237can hang, because the interactive shell within the script session misses EOF and
63ddc7ba 238.B script
c8a550a1 239has no clue when to close the session. See the \fBNOTES\fR section for more information.
c5e7b9fa 240.SH AVAILABILITY
601d12fb 241The script command is part of the util-linux package and is available from
d673b74e 242.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
c5e7b9fa
SK
243Linux Kernel Archive
244.UE .