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:
Then, my admin script looks like this:#!/usr/bin/perl use strict; use warnings; my $tag = shift; while (<>) { print "$tag: $_"; }
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.for host in foo bar baz do ssh $host "update-metadata" 2>&1 > /dev/null | taglines $host & done
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 :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tag lines
by jdporter (Paladin) on Dec 24, 2008 at 19:31 UTC | |
by missingthepoint (Friar) on Dec 26, 2008 at 07:00 UTC | |
by jdporter (Paladin) on Dec 26, 2008 at 12:52 UTC | |
|
Re: Tag lines
by Fletch (Bishop) on Dec 24, 2008 at 19:49 UTC |