LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-16-2012, 10:12 PM   #1
picho
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 05:07 PM.
 
Old 02-17-2012, 04:03 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,580
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
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, 04:41 PM   #3
picho
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, 04:50 PM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ 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, 05:08 PM   #5
picho
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, 05:12 PM   #6
picho
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, 06:46 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
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 06:53 PM.
 
  


Reply


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


All times are GMT -5. The time now is 08:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration