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]

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