{{tag>terminal script logging recording}} ====== 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 [[https://github.com/asciinema/asciinema-player/releases/download/v3.0.0-beta.4/asciinema-player.css|css]] and [[https://github.com/asciinema/asciinema-player/releases/download/v3.0.0-beta.4/asciinema-player.min.js|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//.
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 [[https://github.com/asciinema/asciinema-player#api|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 ====== * [[Play multigigabyte asciinema recordings]] ====== References ====== * https://asciinema.org * https://unix.stackexchange.com/questions/25639/how-to-automatically-record-all-your-terminal-sessions-with-script-utility * https://github.com/theonewolf/TermRecord * https://linoxide.com/linux-terminal-recording-tools/