LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Permanently redirect stdout (https://www.linuxquestions.org/questions/linux-newbie-8/permanently-redirect-stdout-929808/)

picho 02-16-2012 09:12 PM

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.

MensaWater 02-17-2012 03:03 PM

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.

picho 02-17-2012 03:41 PM

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?

T3RM1NVT0R 02-17-2012 03:50 PM

@ 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.

picho 02-17-2012 04:08 PM

T3RM1NVT0R you are a genious. I haven't fully tested it but chances are it's exactly what I needed. Thanks everyone.

picho 02-17-2012 04:12 PM

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'.

theNbomr 02-17-2012 05:46 PM

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.


All times are GMT -5. The time now is 11:00 PM.