xref: /freebsd/usr.bin/script/script.1 (revision 97759ccc715c4b365432c16d763c50eecfcb1100)
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 aeFfkqr
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.El
137.Pp
138The script ends when the forked shell (or command) exits (a
139.Em control-D
140to exit
141the Bourne shell
142.Pf ( Xr sh 1 ) ,
143and
144.Em exit ,
145.Em logout
146or
147.Em control-D
148(if
149.Em ignoreeof
150is not set) for the
151C-shell,
152.Xr csh 1 ) .
153.Pp
154Certain interactive commands, such as
155.Xr vi 1 ,
156create garbage in the typescript file.
157The
158.Nm
159utility works best with commands that do not manipulate the screen.
160The results are meant to emulate a hardcopy terminal, not an addressable one.
161.Sh ENVIRONMENT
162The following environment variables are utilized by
163.Nm :
164.Bl -tag -width SCRIPT
165.It Ev SCRIPT
166The
167.Ev SCRIPT
168environment variable is added to the sub-shell.
169If
170.Ev SCRIPT
171already existed in the users environment,
172its value is overwritten within the sub-shell.
173The value of
174.Ev SCRIPT
175is the name of the
176.Ar typescript
177file.
178.It Ev SHELL
179If the variable
180.Ev SHELL
181exists, the shell forked by
182.Nm
183will be that shell.
184If
185.Ev SHELL
186is not set, the Bourne shell
187is assumed.
188.Pq Most shells set this variable automatically .
189.El
190.Sh EXAMPLES
191Record a simple
192.Xr csh 1
193session with no additional details like input, output, and timestamping:
194.Bd -literal -offset indent
195$ SHELL=/bin/csh script
196Script started, output file is typescript
197% date
198Tue Jan  5 15:08:10 UTC 2021
199% exit
200exit
201
202Script done, output file is typescript
203.Ed
204.Pp
205Now, replay the session recorded in the previous example:
206.Bd -literal -offset indent
207$ cat ./typescript
208Script started on Tue Jan  5 15:08:08 2021
209% date
210Tue Jan  5 15:08:10 UTC 2021
211% exit
212exit
213
214Script done on Tue Jan  5 15:08:13 2021
215.Ed
216.Pp
217Record a
218.Xr csh 1
219session, but this time with additional details like timestamping:
220.Bd -literal -offset indent
221$ SHELL=/bin/csh script -r
222Script started, output file is typescript
223% date
224Tue Jan  5 15:17:11 UTC 2021
225% exit
226exit
227
228Script done, output file is typescript
229.Ed
230.Pp
231In order to replay a sessions recorded with the
232.Fl r
233flag, it is necessary to specify
234.Fl p
235.Po
236.Xr cat 1
237will not work because of all the aditional information stored in the session file
238.Pc .
239Also, let us use
240.Fl d
241to print the whole session at once:
242.Bd -literal -offset indent
243$ script -dp ./typescript
244Script started on Tue Jan  5 15:17:09 2021
245% date
246Tue Jan  5 15:17:11 UTC 2021
247% exit
248exit
249
250Script done on Tue Jan  5 15:17:14 2021
251.Ed
252.Sh SEE ALSO
253.Xr csh 1
254.Po
255for the
256.Em history
257mechanism
258.Pc ,
259.Xr filemon 4
260.Sh HISTORY
261The
262.Nm
263command appeared in
264.Bx 3.0 .
265.Pp
266The
267.Fl d ,
268.Fl p
269and
270.Fl r
271options first appeared in
272.Nx 2.0
273and were ported to
274.Fx 9.2 .
275.Sh BUGS
276The
277.Nm
278utility places
279.Sy everything
280in the log file, including linefeeds and backspaces.
281This is not what the naive user expects.
282.Pp
283It is not possible to specify a command without also naming the script file
284because of argument parsing compatibility issues.
285.Pp
286When running in
287.Fl k
288mode, echo cancelling is far from ideal.
289The slave terminal mode is checked
290for ECHO mode to check when to avoid manual echo logging.
291This does not
292work when the terminal is in a raw mode where
293the program being run is doing manual echo.
294.Pp
295If
296.Nm
297reads zero bytes from the terminal, it switches to a mode when it
298only attempts to read
299once a second until there is data to read.
300This prevents
301.Nm
302from spinning on zero-byte reads, but might cause a 1-second delay in
303processing of user input.
304