Veritas-bu

[Veritas-bu] Veritas NetBackup: Using bpdbjobs in a "tail -f" mode?

2001-12-07 10:35:36
Subject: [Veritas-bu] Veritas NetBackup: Using bpdbjobs in a "tail -f" mode?
From: george AT omniti DOT com (George Schlossnagle)
Date: Fri, 7 Dec 2001 10:35:36 -0500
I use this for jobs being run (see below).  It's not entirely feature rich
(only supports 2 jobs simultaneously and doesn'recheck the job queue), but
basically it works.

Requires perl, curses, time::hires and file::tail.

#!/usr/local/bin/perl
use File::Tail;
use Curses;
use Time::HiRes qw( usleep );

$JOBS_PATH='/usr/openv/netbackup/db/jobs/';  ## ADJUST THIS
$OFFSET = 12;  ## For Curses.

@pids = @ARGV;

unless($pids[0]) {
        open JOBS, "/usr/openv/netbackup/bin/admincmd/bpdbjobs -report|";
        while(<JOBS>) {
                next unless /Active/;
                @els = split;
                print join(':', @els), "\n";
                push @pids, (split)[0];
        }
        close JOBS;
}

($pid1, $pid2) = @pids;
($pid1) || eval { print "No active or specified jobs.\n"; exit; };
foreach my $pid (@pids) {
        open JOBFILE, "$JOBS_PATH$pid";
        while(<JOBFILE>) {
                /^CLASS \d+ (\S+)/ && ($class{$pid} = $1);
                /^SCHEDULE \d+ (\S+)/ && ($sched{$pid} = $1);
        }
}

($fname1) = <$JOBS_PATH$pid1.*t>;
($fname2) = <$JOBS_PATH$pid2.*t>;

$done1 = 1;
$log1 = File::Tail->new(name=>$fname1, tail=>'-1');
$done2 = 0;
$fname2 && ($done2 = 1) && ($log2 = File::Tail->new(name=>$fname2,
tail=>'-1'));

my $this_file_bytes = 0;
my $total_bytes = 0;

initscr();
$a = subwin(24, 78, 1, 1);
$a->attron(A_BOLD);
$a->addstr(0,0, "JOB ID: $pid1");
$a->addstr($OFFSET ,0, "JOB ID: $pid2");
$a->attrset(A_NORMAL);
$a->addstr(1,0, "CLASS: $class{$pid1}    SCHEDULE: $sched{$pid1}");
$a->addstr($OFFSET + 1,0, "CLASS: $class{$pid2}    SCHEDULE:
$sched{$pid2}");

while(1) {
        if($done1 && defined($line = $log1->read)) {
                $done1 = parse($a, 0, $line);
        }
        if($fname2 && $done2 && defined($line2 = $log2->read)) {
                $done2 = parse($a, $OFFSET, $line2);
        }
        unless($done1 || $done2) {
                endwin();
                exit;
        }
}


sub parse() {
  ($win, $offset, $_) = @_;
  if(/^BEGIN_WRITING (\d+)/) {
    $now{$offset} = $1;
    $this_file_bytes{$offset} = 0;
    $total_bytes{$offset} = 0;
    $start_time{$offset} = $1;
    $win->addstr(2 + $offset,0 , "Job Start Time: ".
scalar(localtime($start_time
{$offset})));
   }
  if(/^KBW (\d+) (\d+)/) {
    $now{$offset} = $1;
    $this_file_bytes{$offset} += $2;
    $total_bytes{$offset} += $2;
    $win->clrtoeol(3 + $offset,0);
    $win->addstr(3 + $offset,0, "MBytes written total: " .
sprintf("%6.2f",$total
_bytes{$offset}/1024));
    $win->clrtoeol(4 + $offset,0);
    $win->addstr(4 + $offset,0, "MBytes written this file: " .
sprintf("%6.2f",$t
his_file_bytes{$offset}/1024));
    $win->clrtoeol(5 + $offset,0);
    $win->addstr(5 + $offset,0, "Average for this file: ".
sprintf("%6.2f",(($now
{$offset} - $file_start{$offset})?$this_file_bytes{$offset}/($now{$offset} -
$fil
e_start{$offset}):0)) ." Kb/s");
    $win->clrtoeol(6 + $offset,0);
    $win->addstr(6 + $offset,0, "Average for job: ".
sprintf("%6.2f",(($now{$offs
et} - $start_time{$offset})?$total_bytes{$offset}/($now{$offset} -
$start_time{$o
ffset}):0)) ." Kb/s");
    $win->clrtoeol(7 + $offset,0);
    $win->addstr(7 + $offset,0 , "Update Time: ".
scalar(localtime($now{$offset})
));
  }
  if(/^PATH_WRITTEN (\d+) (\S+)/) {
    $now{$offset} = $1;
    $file_elapsed{$2} = $now{$offset} - $file_start{$offset};
    $file_bytes{$2} = $this_file_bytes{$offset};
    $file_start{$offset} = $1;
    $this_file_bytes{$offset} = 0;
    $files_written{$offset} += 1;
    $win->clrtoeol(7 + $offset,0);
    $win->addstr(7 + $offset,0 , "Update Time: ".
scalar(localtime($now{$offset})
));
    $win->clrtoeol(9+ $offset,0);
    $win->addstr(9 + $offset,0, "Just finished writing $2");
    $win->addstr(10 + $offset,0, "Total files written:
$files_written{$offset}");
  }
  if(/^END_WRITING (\d+)/) {
    $now{$offset} = $1;
    $win->clrtoeol(7 + $offset,0);
    $win->addstr(7 + $offset,0 , "Update Time: ".
scalar(localtime($now{$offset})
));
    $win->attron(A_BOLD);
    $win->addstr(10 + $offset, 0, "Finished.");
    $win->attrset(A_NORMAL);
    $win->addstr(11 + $offset, 0, $now{$offset} - $start_time{$offset}. "
seconds
."  );
    $win->refresh;
    return 0;
  }
#  usleep(50);
  $win->refresh();
  return 1;
}







----- Original Message -----
From: "Smith, David W (IT)" <d AT kla-tencor DOT com>
To: <veritas-bu AT mailman.eng.auburn DOT edu>
Cc: "Smith, David W (IT)" <David.W.Smith AT kla-tencor DOT com>
Sent: Friday, December 07, 2001 10:15 AM
Subject: [Veritas-bu] Veritas NetBackup: Using bpdbjobs in a "tail -f" mode?


>
> Does anyone know of a method to us the bpdbjobs command in like a unix
"tail
> -f" mode, where you can continually monitor jobs being run, etc.
>
> Does this command have a man page? I've looked in the System Admin manual
> and the options are not documented well.
>
> Thanks,
>
>  David W. Smith (David.W.Smith AT kla-tencor DOT com)
>  KLA-Tencor Corporation
>  Telephone: 408-875-6856 (direct)  408-571-2700 (fax)
>  Pager    : 888-476-5501 (numeric) 0951038 AT pagenet DOT net (alpha)
> _______________________________________________
> Veritas-bu maillist  -  Veritas-bu AT mailman.eng.auburn DOT edu
> http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu
>