#!/usr/local/bin/perl # ratiocheck.pl # desc: checks on ratios between the dynamic.dc and the xxxdb.1.dc filesizes # desc: mails results to recipient(s) # wordsettings: # end_autoz # ratiocheck.pl written by Roy Zimmer, Western Michigan University. # Copyright 2004. Freely available to Voyager users. # use at your own risk. # # static data/templates $generic_path = "/m1/voyager/%s/data/"; $dcfile = "dynamic.dc"; $generic_dbfile = "%s.1.dc"; $pctfile = "/tmp/pct50.msg"; # Tell ratiocheck.pl, in the section below, where its .ini file is. # see ratiocheck.ini for other setup details # ########################################################################### # USER CUSTOMIZATION # # You need to tell ratiocheck.pl where its .ini file is. # Put that path inside the double quotes below. # # Example: $inipath = "/usr/local/bin"; # $inipath = ""; # # You need to construct a mail command that tells ratiocheck.pl to send # its result file to someone. Put this command inside the double quotes # below. You must retain the "$pctfile" reference so that your mail # program knows what to mail. # # A generic example: "/usr/bin/mail joe.user\@your.edu < $pctfile" # $mailcommand = ""; # # Do NOT change anything outside this box # unless you know what you are doing! ########################################################################### # get thresholds for your databases open(tfile, "$inipath/ratiocheck.ini"); @tdata = ; close(tfile); %threshold = (); foreach $item (@tdata) { if ($item !~ /^#/) # ignore comment lines { $item =~ s/ *//g; # remove spaces, if any ($db, $thresholdvalue) = split /\|/, $item; $threshold{$db} = $thresholdvalue; } } # start up the output file open(fileout, ">$pctfile") or die "Could not open mail temp file"; printf fileout ("50% rule check on select Voyager databases\n"); # go check 'em foreach $db (sort keys %threshold) {checkit($db);} close(fileout); system($mailcommand); sub checkit() { my ($database) = @_; # set things up $path = sprintf($generic_path, $database); $dbfile = sprintf($generic_dbfile, $database); # get the files' sizes $dcfile_size = -s $path.$dcfile; $dbfile_size = -s $path.$dbfile; # compute the ratio as a percentage $ratio = $dcfile_size / $dbfile_size; $ratio = sprintf("%.4f", $ratio); $ratio = 100 * $ratio; $ratio = sprintf("%.2f", $ratio); #output findings printf fileout ("\n %s ratio is: %s\%\n", $database, $ratio); if ($ratio > $threshold{"$database"}) { printf fileout ("*****ALERT! THRESHOLD OF %s%c EXCEEDED!!! %s\n", sprintf("%.2f",$threshold{"$database"}), 37, '*'x35); } else { printf fileout (" normal...\n"); } }