How to log all standard input/output of a shell script from within itself?

I need to somehow turn on (and off) logging all standard input/output of a shell script from within itself into a file whenever the script executes.

I have considered usingscript command, but it launches a new shell and goes out of my script, until I manually enterexit command.

Any ideas how to implement this functionality?

Message was edited by:

michael.su

[407 byte] By [michael.su] at [2007-11-26 7:18:46]
# 1
# script > file.txt ?Obviously there are more details you are not sharing here.
Codename47 at 2007-7-6 18:58:05 > top of Java-index,General,Sys Admin Best Practices...
# 2
You can do this using 'exec':#!/bin/shexec 1>/var/tmp/stdoutexec 2>/var/tmp/stderrecho 'stdout'echo 'stderr' 1>&2
jrg_work at 2007-7-6 18:58:05 > top of Java-index,General,Sys Admin Best Practices...
# 3

Have you considered doing this:

#!/usr/bin/ksh

set -x

(similarly for all functions you are using in the script).

then just run the script and pipe+tee to a file.

Eg:

./myscript.sh |tee -a myscript.log

This should catch all your input and output and works pretty well for debugging shell scripts.

implicate_order at 2007-7-6 18:58:05 > top of Java-index,General,Sys Admin Best Practices...
# 4

oh! the req was to log from within itself.

I'd say use a wrapper shell script to call the script like in my prev post.

#!/usr/bin/ksh

test -f /my/home/logs/myscript.log && (mv /my/home/logs/myscript.log /my/home/log/myscript.old)

/my/home/bin/myscript.sh | tee -a /my/home/logs/myscript.log

implicate_order at 2007-7-6 18:58:05 > top of Java-index,General,Sys Admin Best Practices...