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