08.28.07
ShowSwap.pl
One of our business units wanted to make sure that “memory == swap” on a multitude of machines, and yours truly was tasked with this project. I wrote up a quick Perl script to gather this information. This supports swap files as well. Please feel free to improve on it.
#!/usr/bin/env perl
$hostname=`hostname`;
open SWAP, “/usr/sbin/swap -l | ” or die “Err: $!\n”;
open MEM, “/usr/sbin/prtconf |” or die “Err: $!\n”;
$count = 0;
while () {
next unless /^\// ;
$count++ ;
/\S+\s+\S+\s+\S+\s+(\S+).*/;
$swap{$count++} += $1*512/1024/1024
}
close (SWAP);
while ( ($k,$v) = each %swap) {
$swapSize += $v ;
}
while () { /\w+\:\s+(\S+)/; $size = $1 } sub linez {
@hmm = (split(//,$hostname));
printf “-” x scalar(@hmm) . “\n”;
}&linez;
printf “$hostname” ;
&linez;
printf “Memory size: $size MB\n”;
printf “Swap size: %.0f MB\n”, $swapSize ;