Dear monks,

I would like to highlight the stderr output somehow in the logs of cron jobs, yet maintain the order of the output the same as if the script were run interactively.

For example, I would like to prepend "@@@@@" to all stderr output in the log so that it's more distinguishable. However, I'd like to keep it in context so that I know what part of the program(s) the statement is coming from.

The base output would be from a command like

find /fst/home/ -name '*ooo*'

where there are lots of

find: /fst/home/m1rxp01/.mozilla: Permission denied

types of lines and the occassional

/fst/home/m1rxp01/.openoffice/share/dict/ooo.

In my shell in emacs, I've somehow got it configured to display stdout in green and stderr in orange. I'd like to log my cron output in a similar way. I've tried stuff such as

system("(((find /fst/home/ -name '*ooo*') | 3>&1 1>&2 2>&3 ) | sed 's/^/STDERR:/')");

but even that puts the STDOUT out of sync with the STDERR, and the files aren't in alphabetical order (in the base case this is true).

I've tried

find /fst/home/ -name '*ooo*' 2>&1 >> h1.log | sed 's/^/STDERR:/' >> h1.log

as well, but with the same mis-timing in the results.

I've tried running the same commands in a Perl script both before and after "unbuffering" STDOUT and STDERR with no change in results.

I know that this is a fairly deep issue, and have spent a day reading up on how Linux handles this, but am coming up empty. Thank you.


In reply to Prepending a string to STDERR output, and logging STDOUT & STDERR synchronously to a file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.