#!/usr/bin/perl
# Copyright (C) 2005-2006 Joshua D. Abraham (jabra@spl0it.org)
#
# 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; either version 2 of the License, or
# any later version.
#
# 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
#
# free.pl
# 1.0
#
# Date: Decemeber 3, 2004
# Purpose: determines the percentage of free space of a given device
#
# the latest version can be found at:
# http://www.spl0it.org/files/free.pl
# 
# 

use strict;

if (@ARGV == 1)
{
	my $device=$ARGV[0];
	my ($used, $size, $free_percent);
	$size=1;
	for (split /\n+/,`df -k |egrep  ^/dev/$device`) {
		split /\s+/,$_;
		$used+=$_[2];
		$size+=$_[1];
	}
	$free_percent=(1-$used/$size) * 100;
	printf ("The percentage of free space on $device is %.2f \%\n",$free_percent);
}
else{
	die "Usage: $0 [device]\n";
}
