User Tools

Site Tools


wiki:record_terminal_sessions

Record terminal sessions

Multiple ways to log terminal sessions in file.

Add to end of .bashrc to start recording session when you open the terminal.

script program

We test for shell's parent process not being script and then run script

test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f $HOME/Documents/terminal_logs/$(date +"%d-%b-%y_%H-%M-%S")_shell.log)

To read the log use “less -R” (see this too https://superuser.com/questions/236930/how-to-clean-up-output-of-linux-script-command)

asciinema

apt install asciinema

Then put this at the end of .bashrc to automatically record session when terminal is opened:

test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'sh' || (asciinema rec $HOME/Documents/terminal_logs/$(date +"%d-%b-%y_%H-%M-%S").cast)

To open the recording in the browser download css and javascript file. Save this html file as asciinema_player.html and change the path to the cast file (example below uses path /07-sij-22_13-45-24.cast.

<html>
<head>
 
  <link rel="stylesheet" type="text/css" href="asciinema-player.css" />
 
</head>
<body>
 
  <div id="demo"></div>
 
  <script src="asciinema-player.min.js"></script>
  <script>
    AsciinemaPlayer.create('/07-sij-22_13-45-24.cast', document.getElementById('demo'), {fit: 'both'});
  </script>
</body>
</html>

Then run

python3 -m http.server

in the directory where you downloaded the above files and in your browser visit http://localhost:8000/asciinema_player.html

You can control the look of the player by passing some options to the AsciinemaPlayer.create constructor in html file. See API examples

python program TermRecord

pip3 install TermRecord
test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (TermRecord -o $HOME/Documents/terminal_logs/$(date +"%d-%b-%y_%H-%M-%S").html)

Tested on

  • Ubuntu 20.04.3

See also

References

wiki/record_terminal_sessions.txt · Last modified: 2023/06/05 14:35 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki