LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Log all of a shell script's I/O to the console and a file (http://www.linuxquestions.org/questions/programming-9/log-all-of-a-shell-scripts-i-o-to-the-console-and-a-file-312415/)

trevelluk 04-12-2005 10:03 AM

Log all of a shell script's I/O to the console and a file
 
Hi everyone, hopefully someone can help me with this.

I've got a very large (interactive) shell script, which performs various administration operations on a PostgreSQL database. It's been suggested that it might be useful for all of the console I/O in this script to be logged to a file, as well as being displayed on the console. I know I can use tee to almost achieve this, but unfortunately this is only logging the output to the file, not the user input. I know I could modify the script so that it writes the user input to the file itself, but this seems like a messy solution to me.

Does anyone know of a way that tee can be used to achieve this affect - or some other way I can do it?

Any advice will be greatly appreciated.

theYinYeti 04-12-2005 10:57 AM

I don't have time to test, but maybe something along those lines:
exec 3<&0- # move current stdin to fd 3.
exec 0< <(tee /inputLogFile 0<&3)
in the script.

Yves.

trevelluk 04-12-2005 11:15 AM

Nope, I just tried that and it locked up the console. I'll have a look at what exactly's going on with those commands, and see if I can get anywhere.

trevelluk 04-14-2005 04:38 AM

Ah well, the spec for the thing's changed now anyway, so the question's academic. Thanks for your suggestion, theYinYeti. If I do find a way to do this, I'll let you know.

jlliagre 04-14-2005 05:56 AM

The "script" command seems to fit exactly to the need.

trevelluk 04-14-2005 06:21 AM

:cool:

I didn't know about that one.

Thanks!

theYinYeti 04-18-2005 06:06 AM

Neither did I! Here at work (cygwin): "bash: script: command not found."
I'll have to try this and see what it does at home...

Yves.

jlliagre 04-18-2005 06:35 AM

Here's a old posting about the issue, may be of help:

http://www.cygwin.com/ml/cygwin/2002-09/msg01371.html

sirclif 04-18-2005 01:40 PM

you could use tee twice with the append option

tee -a logfile | script_file | tee -a logfile

this runs the script_file, tee takes all of its standard and writes it to logfile and the screen, then all standard input is first ran through tee, which writes it to logfile and then passes it off to the script_file


All times are GMT -5. The time now is 10:34 AM.