Any way to split up STDOUT and STDERR, and then recombine in the right order?
OK, the question may be a bit misleading, so here is what I am trying to do:
I have a bunch of jobs in cron, and I would like all the output to eventually end up in a log file in exactly the order it would come out if run interactively. However, I would like to somehow mark the lines that come out via STDERR so that I can say color them or something so I can pick them out more easily. This may be as simple as prepending some predetermined series of characters to all STDERR lines like @@@@@ or such. Is this possible? Thanks |
I suppose you could pipe the STDERR (or STDOUT) output through sed, then push that into a file:
$ binary1 1> log.txt 2>&1 |(sed "s/^/STDERR:/" >> log.txt) (I *think* this would work. I haven't tested it, and I really don't know if it will work properly. Give it a shot and see what happens, I guess...) |
Hmm, doesn't seem to work. Perhaps with parentheses around the first part, thus:
(binary1 1> log.txt) note the 1 before the > is superfluous in my limited experience. |
not working yet, further suggestions welcomed. :)
|
OK, so
(find /lcl/fst/ -name "*ooo*" 1> log.txt) 2>&1 |(sed "s/^/STDERR:/" >> log.txt) Does separate out STDERR and STDOUT, but it doesn't reassemble them in the right order; the STDERR: lines are all at the bottom of the file. I'd like all the lines to be in the same order as emitted. |
(find /lcl/fst/ -name "*ooo*" >> log.txt) 2>&1 |(sed "s/^/STDERR:/" >> log.txt)
assembles the line in CLOSER to the expected order but still not quite. |
Sounds like I need to somehow "un-buffer" stderr. By googling I see this is possible in Perl. Is it possible in a shell?
|
getting closer:
((find /lcl/fst/ -name "*ooo*") 3>&1 1>&2 2>&3 ) | sed 's/^/STDERR:/' gives me what I want to the console; now to redirect the whole shebang into a file! |
Nope, still the wrong order, but at least lines aren't getting interrupted.
|
OK, there HAS to be a way to do this, because I got the idea from emacs. In our implementation here, when you issue a command, stdout and stderr both go to the console, but stdout is the default font color, and the stderr stuff is another color. I just want to replicate this for an HTML page to view cron job status.
|
Anybody else with an idea?
|
All times are GMT -5. The time now is 04:33 PM. |