#!/usr/bin/perl # # $Id: tape_report.pl,v 1.12 2003/01/13 05:28:42 jmates Exp $ # # Copyright (c) 2000, Jeremy Mates. All Rights Reserved. # # Use perldoc on this file for documentation/licensing information. # ###################################################################### # # REQUIREMENTS require 5; use strict; use warnings; ###################################################################### # # MODULES use Carp; use Getopt::Std; use FileHandle; ###################################################################### # # VARIABLES my $VERSION; ($VERSION = '$Revision: 1.12 $ ') =~ s/[^0-9.]//g; my (%opts, $media_script, @report, $e, $o_avail, $o_tld); # change this to reflect location of said script $media_script = '/usr/openv/netbackup/bin/goodies/available_media'; # set defaults for what method used $o_avail = $o_tld = 1; ###################################################################### # # MAIN # parse command-line options getopts('h?at', \%opts); help() if exists $opts{'h'} or exists $opts{'?'}; if (exists $opts{'a'} and not exists $opts{'t'}) { $o_tld = 0; } elsif (exists $opts{'t'} and not exists $opts{'a'}) { $o_avail = 0; } # fire off script, gather output into local data structure unless (open (REPORT, "$media_script |")) { die "Problem running $media_script: $!\n"; } else { while () { # hopefully ID's are all numeric strings! if (m/^\d+/) { my ($id, $media_type, $robot_type, $robot_num, $robot_slot, $side_face, $ret_level, $size, $status) = split; # report is array of anonymous hashes push(@report, { 'id' => $id, 'media_type' => $media_type, 'robot_type' => $robot_type, 'robot_num' => $robot_num, 'robot_slot' => $robot_slot, 'side_face' => $side_face, 'ret_level' => $ret_level, 'size' => $size, 'status' => $status }); } } close (REPORT); } # disable notion of "pages" in resulting format format_lines_per_page STDOUT 999999; # perl doesn't like format_formfeed on a per-handle basis, ergo: $^L = ''; format STDOUT_TOP = The following tapes should be removed from the tape library: Slot Status ID Type Size ---------------------------------------------------------------------- . format STDOUT = @>>> @<<<<< @<<<<<<<< @<<<<< @<<<<<<<<< $e->{'robot_slot'}, $e->{'status'}, $e->{'id'}, $e->{'media_type'}, $e->{'size'} . # look for TLD/FULL tapes & generate report aimed at tape monkey; # need to pre-sort by slot with some non-numeric items (-), therefore # disable meaningless warnings in this situation... no warnings 'numeric'; if ($o_avail) { print "Add these tapes to the library by lowest number:\n\n"; foreach $e ( sort { $a->{'robot_slot'} <=> $b->{'robot_slot'} } @report ) { if ($e->{'robot_type'} eq 'NONE' && $e->{'status'} eq 'AVAILABLE') { write; } } print "\n"; } if ($o_tld) { print "Remove the following tapes from the library:\n\n"; foreach $e ( sort { $a->{'robot_slot'} <=> $b->{'robot_slot'} } @report ) { if ($e->{'robot_type'} eq 'TLD' && $e->{'status'} eq 'FULL') { write; } } } print "\n"; exit; ###################################################################### # # SUBROUTINES # a generic help blarb sub help { print <<"HELP"; Usage: $0 [options] Options: -h/-? Display this message -a Show available media. -t Show TLD media (full tapes in library). Default is to show both. Run perldoc on this script for more documentation. HELP exit; } __END__ ###################################################################### # # DOCUMENTATION =head1 NAME tape_report.pl - parses Netbackup's available_media report. =head1 VERSION $Id: tape_report.pl,v 1.12 2003/01/13 05:28:42 jmates Exp $ =head1 SYNOPSIS $ tape_report.pl | mail -s "Tape Recycle Notification" root =head1 DESCRIPTION A simple little script aimed at getting a list of tapes that must be recycled from the output of the available_media shell script shipped with NetBackup. By default, /usr/openv/netbackup/bin/goodies/available_media is used. The script looks for lines marked with TLD and FULL, which indicate a tape ready to be removed from the library. Modifying the format and contents of the report is simple; the format STDOUT area of the script contains a generic report that can be tweaked to your liking. See the perlform(1) manual page for more details on how format works. =head1 USAGE $ tape_report.pl [options] =head1 OPTIONS Options are as follows: =over 4 =item -a Show available media. =item -t Show TLD media (full tapes in library). =back If neither -a nor -t are specified, the default is the same as -at both being on the command line. =head1 ENVIRONMENT Has the same requirements as the available_media shell script, in addition to perl being installed on the machine in question. =head1 BUGS Please send any bug reports (preferably with a patch) to: jmates@sial.org =head1 SEE ALSO perl(1), perlform(1) =head1 AUTHOR Jeremy Mates, jmates@sial.org =head1 COPYRIGHT Copyright (c) 2000, Jeremy Mates. All Rights Reserved. This file is licensed under the terms of the Artistic License: http://sial.org/artistic_license.txt =cut