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