Free.pl

From ChekMate Security Group

#!/usr/bin/perl
#free.pl
#1.0
# Copyright (C) 2006 Joshua D. Abraham (jabra@ccs.neu.edu)
#
# This program is released under the terms of the GNU General Public License
# (GPL), which is distributed with this software in the file "COPYING".
# The GPL specifies the terms under which users may copy and use this software.
#
#   Name: (c) Josh Abraham
#   Date: Decemeber 3, 2004
#   Purpose: determines the percentage of free space of a given device

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";
}