#!/usr/local/bin/perl
#
# du.pl - summarize hostname, vgdisplay, bdf information from HPUX system
#
# Author: Jim Wildman, 3X
# Date: 2/6/2000
# Revised: none
# This script is designed to combine information about the logical
# volumes on an HP machine with the user level information obtained from
# bdf. It produces a simple text report.
# Use awk like variable names
use English;
# These can be replaced with the equivalent commands.
# What is our hostname?
# $hostname = `cat host`;
$hostname = `hostname`;
# Output of 'vgdisplay'
# @vgs = `cat vg`;
@vgs = `/usr/sbin/vgdisplay` ;
# Output of 'bdf'
# @fss = `cat bdf`;
@fss = `bdf` ;
# Total the PE (Physical Extents) used by this machine
# The information is keyed by the short volume group name
foreach $i (@vgs) {
chomp $i;
# This is the last field of a block, so now we summarize
if( $i =~ /Total PVG/ ) {
# Get rid of the leading '/dev/' from the volume group name
$vg =~ s/^\/dev\/// ;
$fpe{$vg} = $freepe * 4 ;
$tpe{$vg} = $totpe * 4 ;
$ape{$vg} = $allocpe * 4 ;
# Collect some totals for the report
$totalpe += $totpe ;
$totalalloc += $allocpe ;
$totalfree += $freepe ;
$cvg++;
}
if( $i =~ /VG Name/ ) {
($j1,$j2,$vg) = split( " ",$i) ;
} elsif ( $i =~ /Total PE/ ) {
($j1,$j2,$totpe) = split( " ",$i) ;
} elsif ( $i =~ /Alloc PE/ ) {
($j1,$j2,$allocpe) = split( " ",$i) ;
} elsif ( $i =~ /Free PE/ ) {
($j1,$j2,$freepe) = split( " ", $i);
}
}
# Collect the filesystem information by volume group
# bdf returns the information sorted by filesystem, not by volume
# group
$lastvg = $fsname = "" ;
FSS: foreach $i (@fss) {
$tbytes = "" ;
chomp $i;
# First line of the output
next FSS if($i =~ /^Filesystem/ ) ;
# Is this the second line of a continuation?
if($lastvg ne "") {
$i = $lastvg . $i ;
$lastvg = "";
}
($fvg,$tbytes,$ubytes,$fbytes,$percent,$fsname) = split( " ",$i);
# This is the first line of a wrapped line
if ($fsname eq "") {
$lastvg = $fvg;
}
next FSS if($lastvg eq $fvg) ;
# check for NFS mounts
next FSS if($fvg =~ /:/) ;
# Split the volume group to get rid of the '/dev/' and to get the
# logical volume name.
# We can't use the =~ construct here because we need the logical
# volume name.
($junk,$dev,$vg,$lv) = split( /\//, $fvg ) ;
$fsvg{$fsname} = $vg ;
$fslv{$fsname} = $lv ;
$fstbytes{$fsname} = $tbytes ;
$fsubytes{$fsname} = $ubytes ;
$fspercent{$fsname} = $percent ;
$clv++;
}
# This is sort of the header for the report
chomp $hostname ;
print "$hostname has a total of $cvg volume groups and $clv logical volumes\n";
# print the totals as both PE, and megabytes. I'm not sure the math is
# correct, but I will check. (PE ?= 4M)
printf " Total PE = %7.0d Allocated PE = %7.0d Free PE = %7.0d\n",
$totalpe, $totalalloc, $totalfree;
# Convert the PE to Megabytes
$tpem = $totalpe * 4 ;
$fpem = $totalfree * 4 ;
$apem = $totalalloc * 4 ;
printf " Total Meg = %7.0d Allocated Meg = %7.0d Free Meg = %7.0d\n",
$tpem, $apem, $fpem;
# start our summary printouts
# Walk one of the vg lists, sorted by vg
foreach $v (sort keys %tpe) {
print "\n Volume group $v: Total Meg: $tpe{$v} Alloc Meg: $ape{$v} Free Meg: $fpe{$v}\n" ;
# Print header row
printf "\t%-20.20s %12.12s %12.12s %12.12s %6.6s\n",
"File system", "Logical vol", "Total bytes", "Used bytes", "% used" ;
# Walk one of the filesystem lists, sorted by file system. Only
# print items matching our current volume group.
foreach $f (sort keys %fsvg) {
if($fsvg{$f} eq $v) {
printf "\t%-20.20s %12.12s %12.12s %12.12s %6.6s\n",
$f, $fslv{$f}, $fstbytes{$f}, $fsubytes{$f}, $fspercent{$f};
}
}
}