#!/usr/bin/perl -- # -*- Perl -*- # # mountinfo -- prints the current mount statistics for ext[23] filesystems # # Version 1.1 # # Copyright (C) 2002 Norman Walsh, All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 dated June, 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use strict; my %devices = (); # Make it work correctly in /etc/init.d boot sequences if ($ARGV[0] eq 'start' || $ARGV[0] eq 'restart' || $ARGV[0] eq 'status') { shift @ARGV; } elsif ($ARGV[0] eq 'stop') { exit; } # Otherwise, the arguments are the filesystems you want to display if (@ARGV) { foreach my $dev (@ARGV) { $devices{$dev} = "unknown"; } } else { # Otherwise, we get the filesystems from those currently mounted open (MOUNT, "mount | grep ext[23] |"); while () { chop; my $dev = undef; my $point = undef; my @info = split(/\s+/, $_); $dev = $info[0]; $point = $info[2]; $devices{$dev} = $point if $dev; } close (MOUNT); } print "\nMount info:\n"; foreach my $dev (sort keys %devices) { my $curcount = 0; my $maxcount = 0; open (DFS, "/sbin/dumpe2fs $dev 2>/dev/null | grep count |"); while () { $curcount = $1 if /^Mount count:\s*(\d+)/i; $maxcount = $1 if /^Maximum mount count:\s*(\d+)/i; } close (DFS); $_ = " " . $devices{$dev} . ":"; $_ = substr($dev, length($dev)-4) . " " . substr($_, length($_)-16); if ($maxcount <= 0) { print "$_ ??? perhaps not an ext2 partition?"; } else{ my $graphlen = 50; my $usedlen = int($graphlen * $curcount / $maxcount); $usedlen = $graphlen if $curcount > $maxcount; my $unusedlen = $graphlen - $usedlen; my $color = "47"; $color = "43" if ($maxcount - $curcount <= 5); $color = "41" if ($maxcount - $curcount <= 3); printf "%s %2d|", $_, $curcount; print "[30;${color}m"; print "#" x $usedlen; print ""; print "." x $unusedlen; printf "|%2d\n", $maxcount; } } print "\n";