summaryrefslogtreecommitdiffstats
path: root/term-utils/script.1
blob: 49ba582244d8a3d2b7f92c6fbfad86e301d418c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
.\" Copyright (c) 1980, 1990 Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"	@(#)script.1	6.5 (Berkeley) 7/27/91
.\"
.TH SCRIPT "1" "October 2019" "util-linux" "User Commands"
.SH NAME
script \- make typescript of terminal session
.SH SYNOPSIS
.B script
[options]
.RI [ file ]
.SH DESCRIPTION
.B script
makes a typescript of everything on your terminal session.  The terminal
data are stored in raw form to the log file and information about timing
to another (optional) structured log file.  The timing log file is necessary to replay
the session later by
.BR scriptreplay (1)
and to store additional information about the session.
.PP
Since version 2.35,
.B script
supports multiple streams and allows the logging of input and output to separate
files or all the one file.  This version also supports new timing file
which records additional information.  The command
.B scriptreplay \-\-summary
then provides all the information.

.PP
If the argument
.I file
or option \fB\-\-log\-out\fR \fIfile\fR is given,
.B script
saves the dialogue in this
.IR file .
If no filename is given, the dialogue is saved in the file
.IR typescript .
.PP
Note that logging input using \fB\-\-log\-in\fR or \fB\-\-log\-io\fR
may record security-sensitive information
as the log file contains all terminal session input
(e.g., passwords)
independently of the terminal echo flag setting.
.SH OPTIONS
Below, the \fIsize\fR argument may be followed by the multiplicative
suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB
(the "iB" is optional, e.g., "K" has the same meaning as "KiB"), or the suffixes
KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB.
.TP
\fB\-a\fR, \fB\-\-append\fR
Append the output to
.I file
or to
.IR typescript ,
retaining the prior contents.
.TP
\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR
Run the
.I command
rather than an interactive shell.  This makes it easy for a script to capture
the output of a program that behaves differently when its stdout is not a
tty.
.TP
\fB\-E\fR, \fB\-\-echo\fR \fIwhen\fR
This option controls the ECHO flag for the pseudoterminal within the session.
The supported modes are
.IR always ,
.IR never ,
or
.IR auto .
The default is
.I auto
-- in this case, ECHO is disabled if the current standard input is a
terminal iin order to avoid double-echo,
and enabled if standard input is not a terminal
(for example pipe:
.BR "echo date | script" )
to avoid missing input in the session log.
.TP
\fB\-e\fR, \fB\-\-return\fR
Return the exit status of the child process.  Uses the same format as bash
termination on signal termination
(i.e., exit status is 128 + the signal number).  The exit status of
the child process is always stored in the type script file too.
.TP
\fB\-f\fR, \fB\-\-flush\fR
Flush output after each write.  This is nice for telecooperation: one person
does `mkfifo foo; script \-f foo',
and another can supervise in real-time what is
being done using `cat foo'.  Note that flush has an impact on performance; it's
possible to use SIGUSR1 to flush logs on demand.
.TP
\fB\-\-force\fR
Allow the default output file
.I typescript
to be a hard or symbolic link.  The command will follow a symbolic link.
.TP
\fB\-B\fR, \fB\-\-log\-io\fR \fIfile\fR
Log input and output to the same
\fIfile\fR.  Note, this option makes sense only if \fB\-\-log\-timing\fR is
also specified, otherwise it's impossible to separate output and input streams from
the log \fIfile\fR.
.TP
\fB\-I\fR, \fB\-\-log\-in\fR \fIfile\fR
Log input to the \fIfile\fR.  The log output is disabled if only \fB\-\-log\-in\fR
specified.
.sp
Use this logging functionality carefully as it logs all input, including input
when terminal has disabled echo flag (for example, password inputs).
.TP
\fB\-O\fR, \fB\-\-log\-out\fR \fIfile\fR
Log output to the \fIfile\fR.  The default is to log output to the file with
name
.I typescript
if the option \fB\-\-log\-out\fR or \fB\-\-log\-in\fR is not given.  The log
output is disabled if only \fB\-\-log\-in\fR specified.
.TP
\fB\-T\fR, \fB\-\-log\-timing\fR \fIfile\fR
Log timing information to the \fIfile\fR.  Two timing file formats are supported
now.  The classic format is used when only one stream (input or output) logging
is enabled.  The multi-stream format is used on \fB\-\-log\-io\fR or when
\fB\-\-log\-in\fR and \fB\-\-log\-out\fR are used together.
See also \fB\-\-logging\-format\fR.
.TP
\fB\-m\fR, \fB\-\-logging\-format\fR \fIformat\fR
Force use of
.I advanced
or
.I classic
format.  The default is the classic format to log only output and the
advanced format when input as well as output logging is requested.
.sp
.RS
.B Classic format
.PP
The log contains two fields, separated by a space.  The first
field indicates how much time elapsed since the previous output.  The second
field indicates how many characters were output this time.
.sp
.B Advanced (multi-stream) format
.PP
The first field is an entry type identifier
('I'nput, 'O'utput, 'H'eader, 'S'ignal).
The socond field is how much time elapsed since the previous entry,
and the rest of the entry is type-specific data.
.RE
.TP
\fB\-o\fR, \fB\-\-output-limit\fR \fIsize\fR
Limit the size of the typescript and timing files to
.I size
and stop the child process after this size is exceeded.  The calculated
file size does not include the start and done messages that the
.B script
command prepends and appends to the child process output.
Due to buffering, the resulting output file might be larger than the specified value.
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Be quiet (do not write start and done messages to standard output).
.TP
\fB\-t\fR[\fIfile\fR], \fB\-\-timing\fR[=\fIfile\fR]
Output timing data to standard error, or to
.I file
when given.  This option is deprecated in favour of \fB\-\-log\-timing\fR where
the \fIfile\fR argument is not optional.
.TP
\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.TP
\fB\-h\fR, \fB\-\-help\fR
Display help text and exit.
.SH SIGNALS
Upon receiving
.BR SIGUSR1 ,
.B script
immediately flushes the output files.
.SH ENVIRONMENT
The following environment variable is utilized by
.BR script :
.TP
.B SHELL
If the variable
.B SHELL
exists, the shell forked by
.B script
will be that shell.  If
.B SHELL
is not set, the Bourne shell is assumed.  (Most shells set this variable
automatically).
.SH NOTES
The script ends when the forked shell exits (a
.I control-D
for the Bourne shell
.RB ( sh (1p)),
and
.IR exit ,
.I logout
or
.I control-d
(if
.I ignoreeof
is not set) for the
C-shell,
.BR csh (1)).
.PP
Certain interactive commands, such as
.BR vi (1),
create garbage in the typescript file.
.B script
works best with commands that do not manipulate the screen, the results are
meant to emulate a hardcopy terminal.
.PP
It is not recommended to run
.B script
in non-interactive shells.  The inner shell of
.B script
is always interactive, and this could lead to unexpected results.  If you use
.B script
in the shell initialization file, you have to avoid entering an infinite
loop.  You can use for example the \fB\%.profile\fR file, which is read
by login shells only:
.sp
.na
.RS
.nf
if test \-t 0 ; then
    script
    exit
fi
.fi
.RE
.ad
.PP
You should also avoid use of
.B script
in command pipes, as
.B script
can read more input than you would expect.
.SH HISTORY
The
.B script
command appeared in 3.0BSD.
.SH BUGS
.B script
places
.I everything
in the log file, including linefeeds and backspaces.  This is not what the
naive user expects.
.PP
.B script
is primarily designed for interactive terminal sessions.  When stdin
is not a terminal (for example: \fBecho foo | script\fR), then the session
can hang, because the interactive shell within the script session misses EOF and
.B script
has no clue when to close the session.  See the \fBNOTES\fR section for more information.
.SH SEE ALSO
.BR csh (1)
(for the
.I history
mechanism),
.BR scriptreplay (1),
.BR scriptlive (1),
.SH AVAILABILITY
The script command is part of the util-linux package and is available from
.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
Linux Kernel Archive
.UE .