PERL script to print out schedule information in format for import to a spreadsheet.
Updated: 08 Oct 2010 | 3 comments
Descripttion:
Use the Veritas NetBackup master server schedule data to create a comma separated version (.csv) file. Then Excel or other spreadsheet may be used to view schedules. Usefull to provide management persons with information.
===========================================================================================
THE SCRIPT IS AS FOLLOWS
============================================================================================
#!/usr/local/bin/perl -w
#
# Use on Veritas' NetBackup master server
#
# print out schedule information in format for import
# to a spreadsheet.
#
my @DAYS = (
"Sun",
"Sat",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
);
my @TYPE = (
"FULL",
"Unknown",
"Unknown",
"Unknown",
"Cummulative-Incremental",
);
# this is the default install dir for netbackup class data
# yes, readdir is more efficient...
my @class = glob("/usr/openv/netbackup/db/class/*");
my $day_secs = 3600 * 24;
print "CLASS,CLIENT,TYPE,SCHEDULE,DAY,DAYN,WINDOWSTART,WINDOWLENGTH,STRT_SECS,END_SECS\n";
foreach $cls (@class) {
my @clients = ();
my $tmp = $cls;
$tmp =~ s,.*/,,;
# get client list
if ( -f "${cls}/clients" ) {
open(IN,"<${cls}/clients") or die;
while (<IN>) {
my ($clnt) = split(/ /,$_);
push(@clients,$clnt);
}
close(IN);
} else {
push(@clients,"none");
}
my @scheds = glob("${cls}/schedule/*");
foreach $schd (@scheds) {
my @days = ();
my $type = '';
if ( -f "${schd}/days" ) {
open (IN,"<${schd}/days") or die;
while (<IN>) {
my $strt_secs = 0;
my $end_secs = 0;
chomp;
($dy,$start,$duration) =
split(/\s+/,$_);
next if $duration == 0;
$strt_secs = ($dy * $day_secs) + $start;
$end_secs = $strt_secs + $duration;
$dy = "$DAYS[$dy],$dy";
$start = secs($start);
$duration = secs($duration);
push(@days,"$dy,$start,$duration,$strt_secs,$end_secs");
}
close(IN);
}
if ( -f "${schd}/info" ) {
open (IN,"<${schd}/info") or die;
while (<IN>) {
chomp;
($key,$type) = split(/\s+/,$_);
if ( $key eq "SCHED_TYPE" ) {
last;
}
}
close(IN);
}
$type = $TYPE[$type];
my $schd_tmp = $schd;
$schd_tmp =~ s,.*/,,;
foreach $clnt (@clients) {
foreach $start_stop (@days) {
# output comma delimited lines
print "$tmp,$clnt,$type,$schd_tmp,$start_stop\n";
}
}
#print "Schedule: $schd\n";
}
}
sub secs {
my $hr = '';
my $min = '';
my $sec = '';
my $tm = shift;
# convert from sec's to hr:min:sec for printout
if ( $tm > 59 ) {
my $hr = 0;
my $sec = $tm % 60;
my $min = $tm / 60;
if ( $min > 59 ) {
my $tmp = $min % 60;
$hr = $min / 60;
$min = $tmp;
}
$tm = sprintf "%02d:%02d:%02d",$hr,$min,$sec;
} else {
$tm = sprintf "%02d:%02d:%02d",0,0,$tm;
}
return $tm;
}
#END OF SCRIPT Download Filed Under:
Comments
Very excellent script which
Very excellent script which help me lot
Thank youNice script
Thank you
Nice script
Do you have a way to add the storage unit to your script?
nevermind
I figured out the proper settings and made the changes to have it output what I needed. :)
Here is the finished product... note fixed a couple bugs in your original script:
#!/usr/bin/perl -w
#
# Use on Veritas' NetBackup master server
#
# print out schedule information in format for import
# to a spreadsheet.
#
my @DAYS = (
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
);
my @TYPE = (
"FULL",
"Differential-Incremental",
"Cumulative-Incremental",
"User-Backup",
"User-Archive",
);
# this is the default install dir for netbackup class data
# yes, readdir is more efficient...
my @class = glob("/usr/openv/netbackup/db/class/*");
my $day_secs = 3600 * 24;
print "POLICY,STORAGEUNIT,CLIENT,TYPE,SCHEDULE,DAY,DAYN,WINDOWSTART,WINDOWLENGTH,STRT_SECS,END_SECS\n";
foreach $cls (@class) {
my @clients = ();
my $sto = '';
my $tmp = $cls;
$tmp =~ s,.*/,,;
# get client list
if ( -f "${cls}/clients" ) {
open(IN,"<${cls}/clients") or die;
while (<IN>) {
my ($clnt) = split(/ /,$_);
push(@clients,$clnt);
}
close(IN);
} else {
push(@clients,"none");
}
# get storage unit
if ( -f "${cls}/info" ) {
open(IN,"<${cls}/info") or die;
while (<IN>) {
chomp;
($key,$sto) = split(/\s+/,$_);
if ( $key eq "RESIDENCE" ) {
last;
}
}
close(IN);
}
my @scheds = glob("${cls}/schedule/*");
foreach $schd (@scheds) {
my @days = ();
my $type = '';
if ( -f "${schd}/days" ) {
open (IN,"<${schd}/days") or die;
while (<IN>) {
my $strt_secs = 0;
my $end_secs = 0;
chomp;
($dy,$start,$duration) =
split(/\s+/,$_);
next if $duration == 0;
$strt_secs = ($dy * $day_secs) + $start;
$end_secs = $strt_secs + $duration;
$dy = "$DAYS[$dy],$dy";
$start = secs($start);
$duration = secs($duration);
push(@days,"$dy,$start,$duration,$strt_secs,$end_secs");
}
close(IN);
}
if ( -f "${schd}/info" ) {
open (IN,"<${schd}/info") or die;
while (<IN>) {
chomp;
($key,$type) = split(/\s+/,$_);
if ( $key eq "SCHED_TYPE" ) {
last;
}
}
close(IN);
}
$type = $TYPE[$type];
my $schd_tmp = $schd;
$schd_tmp =~ s,.*/,,;
foreach $clnt (@clients) {
foreach $start_stop (@days) {
# output comma delimited lines
# orig print "$tmp,$clnt,$type,$schd_tmp,$start_stop\n";
print "$tmp,$sto,$clnt,$type,$schd_tmp,$start_stop\n";
}
}
#print "Schedule: $schd\n";
}
}
sub secs {
my $hr = '';
my $min = '';
my $sec = '';
my $tm = shift;
# convert from sec's to hr:min:sec for printout
if ( $tm > 59 ) {
my $hr = 0;
my $sec = $tm % 60;
my $min = $tm / 60;
if ( $min > 59 ) {
my $tmp = $min % 60;
$hr = $min / 60;
$min = $tmp;
}
$tm = sprintf "%02d:%02d:%02d",$hr,$min,$sec;
} else {
$tm = sprintf "%02d:%02d:%02d",0,0,$tm;
}
return $tm;
}
#END OF SCRIPT
Would you like to reply?
Login or Register to post your comment.