#!/usr/local/bin/perl -w ############################################################################ # This script will run via root cron at 7:00 am Eastern time each day. # It generates a status report of all client backups that took place during # the past 16 hours (3 pm previous day to 7am current day). ############################################################################ require "/usr/local/libdata/perl-5.003/site_perl/Mail/Send.pm"; use lib '/usr/local/libdata/perl-5.003/site_perl'; use Mail::Mailer; sub send_message { my ($recipient, $subject, @message) = @_; my $msg = new Mail::Send; $msg->to($recipient); $msg->subject($subject); my $fh = $msg->open; print $fh @message; $fh->close; } chop($host=`hostname | cut -d"." -f1`); $today=`date`; $nbbin="/usr/openv/netbackup/bin/admincmd"; $recipient = "prodops-backups\@uu.net"; $subject = sprintf "$host backup report"; # Print report heading $heading = sprintf " NIGHTLY BACKUP STATUS REPORT FROM $host\n $today\n\nCLIENT CLASS NAME SCHEDULE STATUS\n=============== ================================== ========== ======\n"; @message = (@message, $heading); # Retrieve list of clients and store in array @clients=`$nbbin/bpclclients -allunique -noheader | cut -d" " -f3 | cut -d"." -f1`; chomp (@clients); # Get status info for all client backups attempted between 3 pm previous day # and 7 am of current day open STATUS, "$nbbin/bperror -l -hoursago 16 -backstat |"; while () { @fields=split; @client_name=split /\./,$fields[11],2; $stats{$client_name[0]}=[ $fields[13], $fields[15], $fields[18] ]; } close STATUS; # Print backup statuses foreach $client (@clients) { if ($stats{$client}) { $line = sprintf "%-19s%-38s%-15s%-s\n",$client,$stats{$client}[0],$stats{$client}[1],$stats{$client}[2]; } else { $line = sprintf "%-19s No backups were attempted\n", $client; } @message=(@message, $line); } $num_clients=scalar(@clients); $line = sprintf "\n\nTOTAL NUMBER OF CLIENTS: $num_clients\n"; @message=(@message, $line); send_message($recipient, $subject, @message); exit;