Hello -

I need to create a bash script (yes, only bash), that logs everything that
it outputs and all user interaction to a file. On the surface I think that
this should be trivial, and on the first line of the script do this:

[ "$LOG" = '' ] && \
  { export LOG=gralog.`date +%Y%m%d%H%M%S` ; exec script -k /tmp/$LOG $0 $* 2>&1 ; }

Unfortunately, I discover that the script command on linux seems to lag
far behind that on the *BSD platforms, in that the usage on each are:

        Linux:  script [-a] [file]
        BSD:    script [-a] [-k] [-q] [-t time] [file] [command ...]

Since I also have the constraint that this same script must work on common
Linux platforms, I have to come up with an alternative to the script
command. So I think, maybe this will work:

[ "$LOG" = '' ] && \
  { export LOG=mylog.`date +%Y%m%d%H%M%S` ; exec bash -c "$0 $* 2>&1 | tee /tmp/$LOG" 
; }

Yeah, I loose the logging of input information, but it largely works. All
except for one thing, which is that after the several hundred lines of
script execution it finall hits "exit 0" but I don't return to the command
prompt. I do see the line just before the exit in the log file and on the
tty. So I experiment with simplistic variations on the theme above, and
they all terminate as I would expect, i.e.:

#!/bin/bash

[ "$LOG" = '' ] && \
  { export LOG=mylog.`date +%Y%m%d%H%M%S` ; exec bash -c "$0 $* 2>&1 | tee /tmp/$LOG" 
; }

ls -l /tmp

echo -n "prompt: "
read response
echo "You entered '$response'"

# In the real-world case, many more lines of script are here.
# When there are many more lines, the exit below doesn't return to the prompt

exit 0


So, my question becomes, has anyone had to do anything similiar in their
own scripts, and if so what mechanism did you use? Does anyone see
anything obviously wrong in my approach and/or do you know of any issues
that might cause the non-termination of the program when it is made more
complex then the last example?

Thanks in advance - Marc


*****************************************************************
To unsubscribe from this list, send mail to [EMAIL PROTECTED]
with the text 'unsubscribe gnhlug' in the message body.
*****************************************************************

Reply via email to