3

I'm on a tty, with a lots of command inputs, bulk of verbose their output, and some error messages. Now I have to get all those stdin/stdout/stderr texts, in the format displayed in the console screen, dumped to a file. How can I get that done using the inbuilt tools (preferably)?

I don't know if the question is confusing! It's really a simple one.. Suppose I logged into tty1 console terminal, ran some commands (with no logging enabled, because I didn't feel the need to) but suddenly there came certain outputs/messages that I want to dump into a file (or the other option get a pen and a paper).

The reason why I am assuming this could be done is because you can use the shift + PgUp/PgDwn to shift the screen outputs, which means they are still there in the buffer (even if the processing is pipelined)! ..and that is what should be recovered.

  • 1
    Why don't you use redirection? – Registered User Jun 23 '14 at 13:21
  • It's not about redirecting the output of some commands but it's about dumping the contents of entire session.. the inputs, outputs and error messages.. yes I can always use redirection in cases I know I need them in advance, but the Q is for the other case.. while using terminal emulator in GUI session I could just copy the contents and save them to a file, but it doesn't seem to be that easy in the mouseless world of tty.. – precise Jun 23 '14 at 13:33
  • 2
    this answer on AU may be useful.Also read this post on U&L.Finally, have a look at google search results – Registered User Jun 23 '14 at 13:40
  • That's nice too, thanks.. But it's not exactly what I want.. – precise Jun 23 '14 at 13:49
  • @RegisteredUser I see you included a google for me... But starting a script each time I start a terminal is not the way I want it to be. It should be post-jobs and not pre-jobs, if you get what I mean.. – precise Jun 23 '14 at 13:58
5
+200

TTYs use "virtual console memory" devices to buffer their screen content. You can read more about them in man vcs but this will let you get what is on the screen at the current moment.

In practise these are just numbered files in /dev/ that line up with the TTY number. Here's an example I did with TTY2:

$ sudo fold -w$(stty -F /dev/tty2 size | awk '{print $2}') /dev/vcs2

Ubuntu 14.04 LTS bert tty2                                                      

bert login: oli                                                                 
Password:                                                                       
oli@bert:~$ cd test                                                             
oli@bert:~/test$ ls                                                             
Madonna - 10 - Bedtime Story.mp3  output_MP3WRAP.mp3                            
Madonna - 11 - Take A Bow.mp3                                                   
oli@bert:~/test$                                       

The fold -w$(...) there is because the buffered output doesn't appear to have the control characters or newlines I would expect. This simply adds \n at the end of every line.

As TuKsn points out in the comments, you don't have to mess around with all this, you can achieve exactly the same with:

sudo screendump 2

You can stick > tty.log on the end of either command to write the output to a file called tty.log in the current directory:

sudo screendump 2 > tty.log

Again, this will only get you what is on the screen. Even if you increase the scrollback buffer in TTYs, this isn't stored in accessible memory. You can alter that but that involves recompiling the kernel.

That would involve rebooting and losing the current screen so if you can do that there are much easier options for logging future IO, like screen or tmux or just script.

  • is there a memory limit to vcs? In the GUI I've set the terminal profile to use unlimited scroll, but that doesn't seem to apply in the ttys! – precise Aug 1 '14 at 10:10
  • If i use sudo fold -w$(stty -F /dev/tty2 size | awk '{print $2}') /dev/vcs2 or sudo screendump (should be the same) there are only a limited output of the last commands (64 lines?), seems to be there is a memory limit. – TuKsn Aug 1 '14 at 10:25
  • +1 for fold and screendump which does the work but leaves it incomplete, just dumps the last screen.. (and yes, I too liked script but my display seems to be flicker with the screen on) – precise Aug 1 '14 at 10:49
1

Probably you can use a program named screen. It saves all output of Terminal into a file. Have a look at this Ubuntu Forums thread http://ubuntuforums.org/showthread.php?t=1379903. CMIIW.

  • 1
    If I have to trigger the log-process at the start there's script as suggested by @registered-user above.. – precise Aug 1 '14 at 9:30
0

Since I cannot find any keyboard shortcut for Select All, I have found these that might help... https://stackoverflow.com/questions/1536757/selecting-text-in-terminal-without-using-the-mouse A command-line clipboard copy and paste utility?

The first one is screen, which has been suggested, but it seems to have a utility that copies text, so that might work. Enter copy mode with ^A-Esc. Start selecting text with space and end selecting text with space. Insert text with ^A-]

The second one is about pasting the text in the Clipboard to a file. I am completely unsure if any of these will work though... Hope one does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.