Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-16-2012, 09:12 PM   #1
LQ Newbie
Registered: Jun 2009
Posts: 11

Rep: Reputation: 0
Permanently redirect stdout

I want to boot up my linux and send every single output (until I shutdown) to a file instead (or besides) to /dev/tty1.
Can it be done?

Thanks a lot.

Last edited by picho; 02-17-2012 at 04:07 PM.
Old 02-17-2012, 03:03 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,814
Blog Entries: 15

Rep: Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661Reputation: 1661
Surely you don't mean every single output? Many processes run in the background. Terminals send control codes. A single file containing all output would:
a) Likely get very large very fast so is apt to fill up the filesystem.
b) Likely impact your performance for all the writes.
c) Be unusable because you'd not know which command sent which output.

Is it possible what you really want is to save output from a given user's session? If so you should explore the "screen" command. You could launch this is the user's .bashrc or .profile.

For individual commands you can use the "tee" command to send output to different devices:

e.g. "ls -l |tee ls.out" from a terminal session would display the ls -l output on the screen and also send that output to the file ls.out.
Old 02-17-2012, 03:41 PM   #3
LQ Newbie
Registered: Jun 2009
Posts: 11

Original Poster
Rep: Reputation: 0
It's an unattended terminal running certain process. No hardware display attached so I need a way to record what's been happening at the output for diagnosis. I don't expect the output to be any big unless weirdness takes control.
Can't /dev/tty1 be simply redirected to a file for the session lifespan?
Old 02-17-2012, 03:50 PM   #4
Senior Member
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Are you trying to record what happens on a particular terminal session? If yes, then you can use script command. Basically you need to run the script command and it will log everything that will happen on that particular terminal. It will keep recording until you type exit. Once you will type exit it will create a file typescript in the location where you currently are (pwd). You can schedule this via cronjob. File will only get created once you will type exit. You can even rotate the file via cronjob.
Old 02-17-2012, 04:08 PM   #5
LQ Newbie
Registered: Jun 2009
Posts: 11

Original Poster
Rep: Reputation: 0
T3RM1NVT0R you are a genious. I haven't fully tested it but chances are it's exactly what I needed. Thanks everyone.
Old 02-17-2012, 04:12 PM   #6
LQ Newbie
Registered: Jun 2009
Posts: 11

Original Poster
Rep: Reputation: 0
One nice option is:
-f Flush output after each write. This is nice for telecooperation:
One person does 'mkfifo foo; script -f foo' and another can
supervise real-time what is being done using 'cat foo'.
Old 02-17-2012, 05:46 PM   #7
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If real-time monitoring and logging is what you want, then the GNU screen application may also work well. It is a bit of a trick to get an application launched in it at boot time, but once it is launched, and if it is set up in multi-user mode, you can allow arbitrary numbers of concurrent users, and log everything to a file. I do this all the time with a particular application that is intended to run perpetually, but has an interactive console component that a whole group of people need to access from any where with SSH.
--- rod.

Last edited by theNbomr; 02-17-2012 at 05:53 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
redirect AND print stdout samel_tvom Programming 12 10-07-2012 05:37 PM
How to redirect standard stdout to multi stdout ( Bash )? john.daker Programming 4 11-03-2008 11:20 PM
Redirect stdout to xterm window rwengr Programming 2 06-23-2006 01:01 PM
redirect stdout of os.system()? Chowroc Programming 7 03-02-2006 10:56 PM
redirect stdout to a varible Furlinastis Programming 3 12-07-2005 06:01 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:41 PM.

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