xref: /freebsd-14.2/usr.bin/script/script.1 (revision 2c24df87)
1.\" Copyright (c) 1980, 1990, 1993
2.\"	The Regents of the University of California.  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. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"	@(#)script.1	8.1 (Berkeley) 6/6/93
29.\"
30.Dd October 26, 2022
31.Dt SCRIPT 1
32.Os
33.Sh NAME
34.Nm script
35.Nd make typescript of terminal session
36.Sh SYNOPSIS
37.Nm
38.Op Fl aeFfkqrw
39.Op Fl t Ar time
40.Op Ar file Op Ar command ...
41.Nm
42.Fl p
43.Op Fl deq
44.Op Fl T Ar fmt
45.Op Ar file
46.Sh DESCRIPTION
47The
48.Nm
49utility makes a typescript of everything printed on your terminal.
50It is useful for students who need a hardcopy record of an interactive
51session as proof of an assignment, as the typescript file
52can be printed out later with
53.Xr lpr 1 .
54.Pp
55If the argument
56.Ar file
57is given,
58.Nm
59saves all dialogue in
60.Ar file .
61If no file name is given, the typescript is saved in the file
62.Pa typescript .
63.Pp
64If the argument
65.Ar command
66is given,
67.Nm
68will run the specified command with an optional argument vector
69instead of an interactive shell.
70.Pp
71The following options are available:
72.Bl -tag -width "-F pipe"
73.It Fl a
74Append the output to
75.Ar file
76or
77.Pa typescript ,
78retaining the prior contents.
79.It Fl d
80When playing back a session with the
81.Fl p
82flag, do not sleep between records when playing back a timestamped session.
83.It Fl e
84Accepted for compatibility with
85.Em util-linux
86.Nm .
87The child command exit status is always the exit status of
88.Nm .
89.It Fl F
90Immediately flush output after each write.
91This will allow a user to create a named pipe using
92.Xr mkfifo 1
93and another user may watch the live session using a utility like
94.Xr cat 1 .
95.It Fl f
96Create
97.Ar file.filemon
98or
99.Pa typescript.filemon
100using
101.Xr filemon 4 .
102.It Fl k
103Log keys sent to the program as well as output.
104.It Fl p
105Play back a session recorded with the
106.Fl r
107flag in real time.
108.It Fl q
109Run in quiet mode, omit the start, stop and command status messages.
110.It Fl r
111Record a session with input, output, and timestamping.
112.It Fl t Ar time
113Specify the interval at which the script output file will be flushed
114to disk, in seconds.
115A value of 0
116causes
117.Nm
118to flush after every character I/O event.
119The default interval is
12030 seconds.
121.It Fl T Ar fmt
122Implies
123.Fl p ,
124but just reports the time-stamp of each output.
125This is very useful for assessing the timing of events.
126.Pp
127If
128.Ar fmt
129does not contain any
130.Ql %
131characters, it indicates the default format:
132.Ql %n@ %s [%Y-%m-%d %T]%n ,
133which is useful for both tools and humans to read, should be used.
134Note that time-stamps will only be output when different from the
135previous one.
136.It Fl w
137Forward terminal size changes on
138.Dv SIGWINCH .
139.El
140.Pp
141The script ends when the forked shell (or command) exits (a
142.Em control-D
143to exit
144the Bourne shell
145.Pf ( Xr sh 1 ) ,
146and
147.Em exit ,
148.Em logout
149or
150.Em control-D
151(if
152.Em ignoreeof
153is not set) for the
154C-shell,
155.Xr csh 1 ) .
156.Pp
157Certain interactive commands, such as
158.Xr vi 1 ,
159create garbage in the typescript file.
160The
161.Nm
162utility works best with commands that do not manipulate the screen.
163The results are meant to emulate a hardcopy terminal, not an addressable one.
164.Sh ENVIRONMENT
165The following environment variables are utilized by
166.Nm :
167.Bl -tag -width SCRIPT
168.It Ev SCRIPT
169The
170.Ev SCRIPT
171environment variable is added to the sub-shell.
172If
173.Ev SCRIPT
174already existed in the users environment,
175its value is overwritten within the sub-shell.
176The value of
177.Ev SCRIPT
178is the name of the
179.Ar typescript
180file.
181.It Ev SHELL
182If the variable
183.Ev SHELL
184exists, the shell forked by
185.Nm
186will be that shell.
187If
188.Ev SHELL
189is not set, the Bourne shell
190is assumed.
191.Pq Most shells set this variable automatically .
192.El
193.Sh EXAMPLES
194Record a simple
195.Xr csh 1
196session with no additional details like input, output, and timestamping:
197.Bd -literal -offset indent
198$ SHELL=/bin/csh script
199Script started, output file is typescript
200% date
201Tue Jan  5 15:08:10 UTC 2021
202% exit
203exit
204
205Script done, output file is typescript
206.Ed
207.Pp
208Now, replay the session recorded in the previous example:
209.Bd -literal -offset indent
210$ cat ./typescript
211Script started on Tue Jan  5 15:08:08 2021
212% date
213Tue Jan  5 15:08:10 UTC 2021
214% exit
215exit
216
217Script done on Tue Jan  5 15:08:13 2021
218.Ed
219.Pp
220Record a
221.Xr csh 1
222session, but this time with additional details like timestamping:
223.Bd -literal -offset indent
224$ SHELL=/bin/csh script -r
225Script started, output file is typescript
226% date
227Tue Jan  5 15:17:11 UTC 2021
228% exit
229exit
230
231Script done, output file is typescript
232.Ed
233.Pp
234In order to replay a sessions recorded with the
235.Fl r
236flag, it is necessary to specify
237.Fl p
238.Po
239.Xr cat 1
240will not work because of all the aditional information stored in the session file
241.Pc .
242Also, let us use
243.Fl d
244to print the whole session at once:
245.Bd -literal -offset indent
246$ script -dp ./typescript
247Script started on Tue Jan  5 15:17:09 2021
248% date
249Tue Jan  5 15:17:11 UTC 2021
250% exit
251exit
252
253Script done on Tue Jan  5 15:17:14 2021
254.Ed
255.Sh SEE ALSO
256.Xr csh 1
257.Po
258for the
259.Em history
260mechanism
261.Pc ,
262.Xr filemon 4
263.Sh HISTORY
264The
265.Nm
266command appeared in
267.Bx 3.0 .
268.Pp
269The
270.Fl d ,
271.Fl p
272and
273.Fl r
274options first appeared in
275.Nx 2.0
276and were ported to
277.Fx 9.2 .
278.Sh BUGS
279The
280.Nm
281utility places
282.Sy everything
283in the log file, including linefeeds and backspaces.
284This is not what the naive user expects.
285.Pp
286It is not possible to specify a command without also naming the script file
287because of argument parsing compatibility issues.
288.Pp
289When running in
290.Fl k
291mode, echo cancelling is far from ideal.
292The slave terminal mode is checked
293for ECHO mode to check when to avoid manual echo logging.
294This does not
295work when the terminal is in a raw mode where
296the program being run is doing manual echo.
297.Pp
298If
299.Nm
300reads zero bytes from the terminal, it switches to a mode when it
301only attempts to read
302once a second until there is data to read.
303This prevents
304.Nm
305from spinning on zero-byte reads, but might cause a 1-second delay in
306processing of user input.
307