The script command records a terminal session and saves it as a TypeScript file, capturing both input and output. It is best used when a detailed log of terminal activity is required, such as for troubleshooting, documentation, or auditing purposes.
BASIC USAGE
root@oco:~$ script -af termscreen.$$
* -a means append to the log file
* -f means run flush the output of the file after each write in real-time
- Without -f, the output might be buffered, meaning it could be written to the file in chunks rather than immediately.
* termscreen specifies the filename of the file where the terminal session will be recorded
* the $$ is a special shell variable that expands to the process ID (PID) of the currently running shell
- the $$ ensures that the filename is unique for each script session
root@oco:~$ exit
root@oco:~$ cat termscreen.{PID}
BASIC USAGE WITH PLAYBACK OPTIONS
root@oco:~$ script --t=scriptTimingFile.$$ -af scriptFile.$$
* the --t option specifies the timing data
* the "scriptTimingFile.$$" file contains the timing data
* -a means append to the log file
* -f means run flush the output of the file after each write in real-time
- Without -f, the output might be buffered, meaning it could be written to the file in chunks rather than immediately.
* the "scriptFile.$$" file contains input & output data
* the $$ is a special shell variable that expands to the process ID (PID) of the currently running shell
- the $$ ensures that the filename is unique for each script session
* use Ctrl-D to end and save the file
root@oco:~$ cat scriptTimingFile.{PID}
root@oco:~$ cat scriptFile.{PID}
root@oco:~$ scriptreplay --timing=scriptTimingFile.{PID} scriptFile.{PID}