LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-12-2005, 11:03 AM   #1
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
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.
 
Old 04-12-2005, 11:57 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
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.
 
Old 04-12-2005, 12:15 PM   #3
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Original Poster
Rep: Reputation: 32
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.
 
Old 04-14-2005, 05:38 AM   #4
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Original Poster
Rep: Reputation: 32
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.
 
Old 04-14-2005, 06:56 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
The "script" command seems to fit exactly to the need.
 
Old 04-14-2005, 07:21 AM   #6
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Original Poster
Rep: Reputation: 32


I didn't know about that one.

Thanks!
 
Old 04-18-2005, 07:06 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
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.
 
Old 04-18-2005, 07:35 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

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

http://www.cygwin.com/ml/cygwin/2002-09/msg01371.html
 
Old 04-18-2005, 02:40 PM   #9
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
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
 
  


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
Shell script's name doesn't appear in ps ealdaz Linux - General 12 08-21-2005 10:27 PM
I'd like my cake & eat it too please! Log to both console and file ericcarlson Linux - Software 1 03-01-2005 04:07 AM
How to control log file size in /var/log? yan Linux - General 2 10-13-2003 06:00 PM
IPTables logging going to console not the log file arobinson74 Linux - Networking 2 04-01-2003 02:20 AM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 09:38 PM


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