ADSM-L

[ADSM-L] Colorful console mode output

2009-08-21 19:01:07
Subject: [ADSM-L] Colorful console mode output
From: Michael Green <mishagreen AT GMAIL DOT COM>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Sat, 22 Aug 2009 02:00:08 +0300
If you are like me and find it helpful to have administrative client
running in console mode (dsmadmc -console) while performing
administrative work on your server, you might find this little script
(below) handy. I also have a habit of leaving dsmadmc -console running
for prolonged periods of time in background and then when a problem
strikes I scroll the buffer up in order to see where and why it all
started. IMHO it's more convinient then fishing the details with 'q
act'.
All good, but one of the great inconveniences with 'dsmadmc -console'
that it doesn't pre/append timestamps to its messages as they enter
terminal. Also they are all of the same color (whatever foreground
color of your terminal is set to) and since the vast majority of the
messages are of ANR????I kind it might be difficult to spot, for
example, the error messages which under normal conditions are few and
far between.

So this is what this script does:
- executes dsmadmc -console
- prints out each message as it pops up prepended by current timestamp.
- colors the ANR????E, ANR????D and ANR????W messages making them
stand out and easy to spot.

Color schema that I've chosen is suitable for simple black-on-white
terminals. Of course your terminal must support ASCII escape sequences
for you to see the colors. xterm does support them and, perhaps, is
the most compatible and standard compliant terminal out there. Also I
tested the script with Terminal.app on MacOS X 10.5 and it works fine,
although the colors appear to be a bit different than those in xterm.

My apologies to any color blind people on the list. They still can
benefit from seeing the timestamps though.

How to use it:
1. Save this script to a file.
2. Edit the $dsmadmBin,$adminID,$adminPass variables.
3. Make the script file executable and run it. To terminate it, use Ctrl-C.

#!/usr/bin/perl

use POSIX qw(strftime); # This get us a timestamp for every line
that's processed below.

## You probably need to edit the three lines below.
my $dsmadmBin = "/opt/tivoli/tsm/client/ba/bin/dsmadmc";  # Path to dsmadmc
my $adminID = "admin";                                  # TSM admin username
my $adminPass = "admin";                                # TSM admin password

## Invoke the 'dsmadmc' binary with appropriate user/pass (from above)
my $dscl = "$dsmadmBin -consolemode -id=$adminID -password=$adminPass";
open DSCL, "$dscl|" or die "cannot execute dscl: $!";

## This block  of three lines is responsible for catching Ctrl-C
my $int_counter = 0;
sub int_handler { $int_counter++ }
$SIG{'INT'} = 'int_handler';

while (<DSCL>) {
        chomp;

        if ( $int_counter ) {
                print "Ctrl-C detected, cleaning up...";
                last;
        }

        if    (/(?:ANR\d{4}I)\s+(?:[\d\D]+)/) {
                print "^[[38;5;243m", strftime "%m\/%d %H:%M:%S", localtime;
                print "^[[0m $_\n";
        }
        elsif (/(?:ANR\d{4}W)\s+(?:[\d\D]+)/) {
                print "^[[38;5;243m", strftime "%m\/%d %H:%M:%S", localtime;
                print "^[[38;5;51m ${_}^[[0m\n";
        }
        elsif (/(?:ANR\d{4}E)\s+(?:[\d\D]+)/) {
                print "^[[38;5;243m", strftime "%m\/%d %H:%M:%S", localtime;
                print "^[[38;5;202m ${_}^[[0m\n";
        }
        elsif (/(?:ANR\d{4}D)\s+(?:[\d\D]+)/) {
                print "^[[38;5;243m", strftime "%m\/%d %H:%M:%S", localtime;
                print "^[[38;5;129m ${_}^[[0m\n";
        }
        else {
                print "^[[38;5;243m", strftime "%m\/%d %H:%M:%S", localtime;
                print "^[[0m $_\n";
        }
}

close DSCL;
print "done!\n";

--
Warm regards,
Michael Green

<Prev in Thread] Current Thread [Next in Thread>