In article <
b069b080-7014-4b52...@googlegroups.com>,
shellguest <
amor...@gmail.com> wrote:
...
>- I now need a logfile for everything.
>- The log should be plaintext, not going to syslog.
>- Log should contain all statement from both STDOUT and STDERR.
>- Log should get a timestamp with each line as prefix. `date` : thelogline
>
>- The timestamp should ONLY be in the Logfile, NOT on STDOUT.
>- Though STDOUT and STDERR should be on the screen. But NO timestamp as
>a prefix.
I solved exactly this problem some time back, using the greatest Unix tool
of them all - Expect.
Here's the Expect script:
--- Cut Here ---
#!/usr/bin/expect --
# Post process the log file with:
# awk '-F\r' '{print $2,$1}' /tmp/typescript | less
log_file -noappend /tmp/typescript
eval spawn $argv
interact -o "\n" { send_user [timestamp -format %c\n] }
--- Cut Here ---
Usage is something like: ./AboveScript ./yourscript
Caveat: Yes, this is the lazy way - and I've since learned how to do it all
in Expect instead of having to post-process with AWK. Still, the above
works, and it is pretty good. Figuring out how to do it more cleanly is
left as an exercise for the reader...
--
A liberal, a moderate, and a conservative walk into a bar...
Bartender says, "Hi, Mitt!"