3

Is it possible to turn on logging feature by default in xterm?

Lets say for example, I have example program in c that give an output in xterm everytime i ran the program from default bash terminal in linux. And I want to save the output that shows in xterm into a file everytime the programs is run.

I'm using centos7_x86_64 fyi Thanks.

Aixeta
  • 43
  • 1
  • 4
  • Just redirect the output from the program to a file. –  Feb 13 '18 at 04:12
  • actually, the program is open source project to run embedded software simulation. At first, It provides Virtual Box that has full installed featured, everytime I ran the simulation, then xterm windows will show the output automatically, and when I closed the xterm it was given output file. – Aixeta Feb 14 '18 at 09:11
  • Then, I want to try to install the program in my Virtual Box environment (newer os), but it seems there is a different configuration in xterm. It cannot give the xterm output file which is as like the original Virtual Box – Aixeta Feb 14 '18 at 09:18
  • Can't log to file, else I would have done it! – Owl Mar 29 '19 at 13:47
  • 1
    Great question - why it's voted down is beyond me. – Owl Mar 29 '19 at 13:49
  • This isn't a *programming question*. For an **answer**, see [this](https://unix.stackexchange.com/questions/302544/resource-name-for-xterms-logging-filename/302643#302643). – Thomas Dickey Mar 29 '19 at 23:03
  • 1
    At the same time, nearly every programmer at some point needs to log something or check some output, therefore it's directly related to coding. – Owl Apr 30 '19 at 11:53

3 Answers3

3

In Windowmaker:

Hold down ctrl + left click in xterm window (on the terminal text), click on "log to file".

A cool thing to do is when you're coding, log the terminal, and then when you cat the Xterm log, you see coding in fast forward. If you wanted you could video it.

Note that there are also other menus in xterm, accessible using Ctrl+Left Click, Ctrl+Middle Click, Ctrl+Right Click.

Log file will be in the directory that you launched Xterm from, and will be in the format: Xterm.log.<hostname>.<date>.<time>.log.

This is a very good question, there's no reason to mark down a question like this.

Owl
  • 1,446
  • 14
  • 20
0

It can be done in two ways:

  1. Using script:

    xterm -e script mylogfile -c "someCommand -i input_file -o output_file -f someArg"
    
  2. Redirect to a file:

    xterm -e 'someCommand --arguments 2>&1> /path/to/mylogfile'
    
Vikram Hosakote
  • 3,528
  • 12
  • 23
  • Be VERY WARY of `script`. It has significant limitations regarding how it handles command, pipes or anything thing that manipulates the screen. It was **made for students who need a hardcopy record of an interactive session as proof of an assignment** not for general redirection use. – David C. Rankin Feb 13 '18 at 05:54
0

I do essentially this with "terminal-window", mrxvt, "hcm" and "pypty".

terminal-window wraps mrxvt, just filling in some commandline options. mrxvt is a lightweight, multitabbed, nonunicode terminal emulator not dissimilar to xterm.

hcm is a GUI that makes it easy to run a shell (or other command) on a remote host. It can also start an mrxvt with remote ssh's without requiring the GUI if you prefer (using hcm-term).

pypty is a /usr/bin/script reimplementation that is written in Python. It is not significantly different from /usr/bin/script, except it gives a "dated files mode", that allows you to have one file per pseudo terminal per day. So if you leave a shell logged in overnight, you get one file per day - this tends to make it easier to find what you're looking for.

All this combines to give you pseudo terminal logging with great ease. Commands are run on remote hosts, but logged locally. Just start a "fancy terminal-window" (or use hcm-term), and everything you see on the screen plus control characters (but not nonechoed passwords) will be logged under ~/.hcm/logs/<year>/<month>/<day>/* .

Also, if you hit the shell button in the lower right of mrxvt, you get another ssh session into the same remote host, which is also logged locally (to a different file under ~/.hcm/logs/...). When I started making use of that feature, I had no idea how much I would grow to like it.

You can obtain them from http://stromberg.dnsalias.org/~strombrg/hcm/ There's a video there that shows how easy it is to set up and get started with.

BTW, fancy terminal-window sets up $PS0 or "trap DEBUG" to give you command start times and finish times. It's great for post mortems. It does this without replacing any of the usual bash startup files.

I wrote terminal-window, hcm and pypty, but I can't take credit for mrxvt. :)

HTH

dstromberg
  • 6,954
  • 1
  • 26
  • 27