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. |
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. |
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.
|
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.
|
The "script" command seems to fit exactly to the need.
|
:cool:
I didn't know about that one. Thanks! |
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. |
Here's a old posting about the issue, may be of help:
http://www.cygwin.com/ml/cygwin/2002-09/msg01371.html |
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 06:59 PM. |