ADSM-L

Re: [ADSM-L] Colorful console mode output

2009-08-24 09:04:42
Subject: Re: [ADSM-L] Colorful console mode output
From: Andrew Raibeck <storman AT US.IBM DOT COM>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Mon, 24 Aug 2009 09:02:07 -0400
I took a crack at playing with Michael's script and came up with this
solution. I think the original script uses fancier XTerm colors, but I've
been able to make this version work on Windows, Mac OS X 10.5, and SUSE
Linux 9. On Windows, I use CTRL-BREAK to break out of the script.

The colors I used are:

- Informational messages: white on black
- Warning messages: bold yellow on black
- Error messages: bold red on black
- 'D' error messages (ANRnnnnD): bold white on red

You can adjust the colors according to the perldoc for the Term::ANSIColor
module:

   perldoc Term::ANSIColor

This will show you the different constants you can use (see the
"DESCRIPTION" section).

Here is the code (contains no hidden control characters):

#!/usr/bin/perl
use strict;

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

if ($^O =~ m/^MSWin32/) {
        require Win32::Console::ANSI;
}

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

$SIG{INT} = 'int_handler';
$SIG{HUP} = 'int_handler';
$SIG{QUIT} = 'int_handler';
$SIG{PIPE} = 'int_handler';
$SIG{STOP} = 'int_handler';
$SIG{ABRT} = 'int_handler';
$SIG{TRAP} = 'int_handler';
$SIG{TERM} = 'int_handler';

## You probably need to edit the three lines below.
my $dsmadmBin = "c:\\tsm\\baclient\\dsmadmc";  # Path to dsmadmc
my $adminID = "admin";                                  # TSM admin
username
my $adminPass = "xxxxxx";                                # 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: $!";

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

        if    (/(?:ANR\d{4}I)\s+(?:[\d\D]+)/) {
                print WHITE, ON_BLACK, strftime "%m\/%d %H:%M:%S ",
localtime;
                print WHITE, ON_BLACK, $_, RESET;
        }
        elsif (/(?:ANR\d{4}W)\s+(?:[\d\D]+)/) {
                print WHITE, ON_BLACK, strftime "%m\/%d %H:%M:%S ",
localtime;
                print YELLOW, BOLD, ON_BLACK, $_, RESET;
        }
        elsif (/(?:ANR\d{4}E)\s+(?:[\d\D]+)/) {
                print WHITE, ON_BLACK, strftime "%m\/%d %H:%M:%S ",
localtime;
                print RED, BOLD, ON_BLACK, $_, RESET;
        }
        elsif (/(?:ANR\d{4}D)\s+(?:[\d\D]+)/) {
                print WHITE, ON_BLACK, strftime "%m\/%d %H:%M:%S ",
localtime;
                print WHITE, BOLD, ON_RED, $_, RESET;
        }
        else {
                print WHITE, ON_BLACK, strftime "%m\/%d %H:%M:%S ",
localtime;
                print WHITE, ON_BLACK, $_, RESET;
        }
}

close DSCL;
print "done!\n";


Andy Raibeck
IBM Software Group
Tivoli Storage Manager Client Product Development
Level 3 Team Lead
Internal Notes e-mail: Andrew Raibeck/Hartford/IBM@IBMUS
Internet e-mail: storman AT us.ibm DOT com

IBM Tivoli Storage Manager support web page:
http://www.ibm.com/software/sysmgmt/products/support/IBMTivoliStorageManager.html


The only dumb question is the one that goes unasked.
The command line is your friend.
"Good enough" is the enemy of excellence.

"ADSM: Dist Stor Manager" <ADSM-L AT VM.MARIST DOT EDU> wrote on 08/22/2009
01:44:22 AM:

> [image removed]
>
> Re: Colorful console mode output
>
> Yudi Darmadi
>
> to:
>
> ADSM-L
>
> 08/22/2009 03:34 AM
>
> Sent by:
>
> "ADSM: Dist Stor Manager" <ADSM-L AT VM.MARIST DOT EDU>
>
> Please respond to "ADSM: Dist Stor Manager"
>
> What about windows console? What modification should i do in order to
make
> that script runs?
>
>
> Best Regards,
>
>
> Yudi Darmadi
> PT Niagaprima Paramitra
> Jl. KH Ahmad Dahlan No.25  Kebayoran Baru, Jakarta Selatan 12130
> Phone: 021-72799949; Fax: 021-72799950; Mobile: 081905530830
> http://www.niagaprima.com
>
> ----- Original Message -----
> From: "Stef Coene" <stef.coene AT DOCUM DOT ORG>
> To: <ADSM-L AT VM.MARIST DOT EDU>
> Sent: Saturday, August 22, 2009 11:59 AM
> Subject: Re: [ADSM-L] Colorful console mode output
>
>
> > On Saturday 22 August 2009, Michael Green wrote:
> >> 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.
> > Nice scripts (I have something similar), but I had to replace ^[ with
\033
> > for
> > the colors to work on my linux box.
> >
> >
> > Stef