Automatically logging terminal content

Is there a way to automatically log in terminal content? Or any app available?

  1. open a terminal
  2. type this
bash | tee logfile
  1. Now do the things you wanted to do in the terminal
  2. afterwards, type this:
exit
less logfile
1 Like

Well, yes. There are multiple ways to log in during one session. I meant to run it as a default without having to start and stop it. I can see that guys have created sets of scripts for that, but I was wondering if there is an option in MATE Terminal or an application, which I would just install.

You are looking for script [options] [file] command.

3 Likes

Hi Juan

Here is what you want:

Open the menueditor:
menuedit

Create a new menuitem:

And that is all. You now have a logging terminal. It puts the output of all "logterm" terminal sessions in one logfile.

If you want a logfile per "logterm" terminal session (using several "logterms" at the same time), you can change the menuitem to this:
Screenshot at 2024-07-08 18-42-25

This all thanks to Eugene (@ugnvs) for mentioning the script command :slight_smile:

4 Likes

Oh, by the way:
If the description above is too complicated and you want an automatically generated menuitem you can copy/paste the code block below in a terminal and press enter:

cat <<\EOF > "$HOME/.local/share/applications/logterm.desktop"
#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=mate-terminal -x bash -c "script -f script_$$"
Icon=xterm-color
Name=logterm
Comment=logging terminal
EOF
chmod a+x "$HOME/.local/share/applications/logterm.desktop"
3 Likes

Nice, but I have some unrecognized characters in the output. Maybe because of bad encoding or a different line ending?

Those are color coding characters.

if you use 'cat' to display the file you will see the colors.

2 Likes