Revision: 6425
http://ipcop.svn.sourceforge.net/ipcop/?rev=6425&view=rev
Author: owes
Date: 2012-02-27 12:15:21 +0000 (Mon, 27 Feb 2012)
Log Message:
-----------
Add option to return used space as percentage
Modified Paths:
--------------
ipcop/trunk/src/libs/general-functions.pl
Modified: ipcop/trunk/src/libs/general-functions.pl
===================================================================
--- ipcop/trunk/src/libs/general-functions.pl 2012-02-26 21:15:55 UTC (rev
6424)
+++ ipcop/trunk/src/libs/general-functions.pl 2012-02-27 12:15:21 UTC (rev
6425)
@@ -965,22 +965,36 @@
}
#
-# Get available space on partition in MiB.
+# Get available space on partition in MiB
+# or percentage in use on partition.
# Return space on /root if called without parameter.
#
sub getavailabledisk
{
my $where = '/root';
$where = shift if (defined($_[0]));
+ my $which = 'free';
+ $which = shift if (defined($_[0]));
open(XX, "/bin/df -B M $where | grep -v Filesystem |");
my $df = <XX>;
close(XX);
my ($device, $size, $used, $free, $percent) = split(' ', $df);
- $free =~ m/^(\d+)M$/;
- $free = $1;
- return $free;
+ if ($which eq 'use') {
+ # percentage, strip % character
+ $percent =~ m/^(\d+)\%$/;
+ $percent = $1;
+
+ return $percent;
+ }
+ else {
+ # available space, strip M character
+ $free =~ m/^(\d+)M$/;
+ $free = $1;
+
+ return $free;
+ }
}
#
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Ipcop-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ipcop-svn