LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-06-2010, 11:45 AM   #1
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Rep: Reputation: 41
Redirect ALL terminal output to file and screen (for entire session)


Is there one command that will let me record an entire terminal session (with any possible errors) to a text file while also seeing all output on screen too?

I know it can be done for individual commands, but I'm looking to do this for an entire session where the individual commands will be normal (i.e., not piped into tee, etc.).

It would be even better if the command prompt is captured too. The obvious utility of this makes me think someone surely has come up with a solution long ago (probably in the 60's).

(I'm sure it goes without saying, but subsequent output in that session should be appended to the file. The file should contain the full history, with all output and errors, of the session.)

Last edited by Mountain; 07-06-2010 at 11:58 AM. Reason: added parenthetical
 
Old 07-06-2010, 12:09 PM   #2
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
OK, so I found out about script (man script).
Is this the only solution? It would be great to have an output file that looks more like what I see on the screen (i.e., without showing all the special non-printing characters).
 
Old 07-06-2010, 12:10 PM   #3
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Code:
man 1 script
 
Old 07-06-2010, 12:23 PM   #4
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
Quote:
Originally Posted by AlucardZero View Post
Code:
man 1 script
Yes, I already read the man page for script as I said. I do not see anything in there about cleaning up the non-printing chars from the output. Am I missing something? Thanks
 
Old 07-06-2010, 12:25 PM   #5
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
You posted at the same time I was posting and I did not see your reply.
 
Old 07-06-2010, 12:30 PM   #6
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
OK, found at least one solution here:
http://www.ibm.com/developerworks/ai...ca=drs-#script

Code:
#!/bin/bash

    if [ $# -ne 2 ] ; then 
      echo "Usage: cleanup script-file output-file"
      exit
    fi

    cat $1 | \
      perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' |\
        col -b > $2
 
Old 07-06-2010, 03:05 PM   #7
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by Mountain View Post
Is there one command that will let me record an entire terminal session (with any possible errors) to a text file while also seeing all output on screen too?
Take a look at the 'screen' command. Using the logging option (-L)
whatever you type and whatever is output to STDERR or STDOUT goes into the log file.

While 'screen' is intended to permit multiple terminal or console sessions connected to a single terminal, the logging feature is at least as important for me.

~~~ 0;-Dan
 
1 members found this post helpful.
Old 07-06-2010, 04:25 PM   #8
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
Quote:
Originally Posted by SaintDanBert View Post
Take a look at the 'screen' command. Using the logging option (-L)
whatever you type and whatever is output to STDERR or STDOUT goes into the log file.

While 'screen' is intended to permit multiple terminal or console sessions connected to a single terminal, the logging feature is at least as important for me.

~~~ 0;-Dan
Thank you. It's nice to have another option in addition to script.

If I understand correctly, I simply open konsole and type "screen -L". then I do whatever work I planned to do in the terminal session. When finished, I type "exit". The log is found in screenlog.0 (or generally, screenlog.N, I presume).

The output doesn't need to be run through a cleanup script.
 
Old 07-06-2010, 05:54 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Another option could be to use 'rootsh'. While 'rootsh' can be started and used like 'screen' or 'script' it is a shell wrapper. So in contrast to the others it can be used as a login shell, recording input and output without requiring the user to remember to start it and without user intervention. Logs must be ran through a scrubber though, yours will work just fine.
 
1 members found this post helpful.
Old 07-08-2010, 10:50 AM   #10
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by Mountain View Post
...
The output doesn't need to be run through a cleanup script.
It is human readable without intervention. Since STDIN and STDOUT/ERR are mixed, you will need to scrub the log if you want a script for later execution.
~~~ );-Dan
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: How to Redirect Output to File, AND Still Have it on Screen edwin11 Linux - Software 27 10-20-2017 03:45 AM
Bash Scripting: Redirect output of entire script to file & screen Kristijan Programming 3 10-12-2017 03:17 PM
Redirect terminal output to file AND terminal shan Linux - General 3 09-29-2006 08:36 AM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
how to redirect the output of a terminal? cpukiller Linux - Networking 5 11-10-2004 07:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration