Knowledge Base Article

PERL script to print out schedule information in format for import to a spreadsheet.

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
Published 15 years ago
Version 1.0

20 Comments