One of my system administration scripts does a bunch of stuff to a shared filesystem, and then goes to each of the other hosts (in parallel) to tell each one to update their metadata. Unfortunately, when something goes wrong, its output comes back to the primary machine, and I don't know where it's coming from for further diagnosis. So, a short script:

#!/usr/bin/perl use strict; use warnings; my $tag = shift; while (<>) { print "$tag: $_"; }
Then, my admin script looks like this:
for host in foo bar baz do ssh $host "update-metadata" 2>&1 > /dev/null | taglines $host & done
Now I know when bar has a problem that foo and baz don't: the problem lines all show up with "bar: " in front. I've also discarded stdout, and only tag stderr. This comes in very handy for me. Nothing really novel about the code - it's all fairly obvious (and I'm sure someone'll show it as a one-liner). It's more of another way to approach a problem that perl makes really, really trivial.

Update: to answer Fletch's question: because the update-metadata tools create FAR too much ugly noise on stdout, and I run this all via cron, so I'll just end up with ugly-lookin' emails. But, that's my use-case. I can see where your solution would come in handy, too, though at that point I'd likely use perl to kick off the ssh, too, and use IPC::Open3 to capture and label everything. rewrite.pl -o "$host O: " -e "$host E: " -- ssh $host "update-metadata" would be the interface... but it's no longer just a short snippet of code :-)


In reply to Tag lines by Tanktalus

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.