CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Used space on server



Aug 25, 2000, 2:52 AM

Post #1 of 5 (1431 views)
Used space on server Can't Post


I want to check how must space is used on my server at v.e. hypermart.

I found this script on the net but it can only be run from the command line. I do not have tellnet access so it will not works for me. Is it possible to make it work from the browser.

Article 5272 of comp.lang.perl:
Xref: comp.lang.perl:5272
Newsgroups: comp.lang.perl
From: (Aaron Sherman)
Subject: Re: determining available disk space
In-Reply-To:'s message of Fri, 20 Aug 1993 11:29:43 GMT
Message-ID: <>
Sender: news@fmrco.uucp
Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
References: <>
Date: Tue, 24 Aug 1993 19:30:15 GMT
Lines: 157

>>>>> (Jeff Moskow) said:

jeff> Is there any machine independent way of determining the about of
jeff> available disk space on a particular partition? Basically, I
jeff> want to know if I have enough space to complete an operation
jeff> before I begin. I can certainly execute a df and parse the
jeff> results, but this requires additional code for each new system
jeff> that the script will support. Am I missing something?

Well, I can offer the following.

This is a script which parses df output on Suns, and if we get enough
people to get it to work on their systems, then we will have a
general-purpose program.

I call this dfscan, and it works in a similar fashion to printf, et
al. To use it, you just need to execute dfscan with a format string,
and any arguments that you want passed on to df. So, to find out how
much space is used on /usr, just type "dfscan %c /usr".


# Scan output of df and provide it via command-line options
# By Aaron Sherman (I-Kinetics, Inc.), 1993
# $Id$

$0 =~ s/^.*\///;
$usage = "Usage: $0 [-f <file>] [-h <hostname>] [--]
<format> [<df options>]\n";
$file = undef;
$format = undef;
%mapping= ( # Mapping of format letter to field number
'f',0, # Filesystem
't',1, # Total space
'u',2, # Space used
'a',3, # Space available
'c',4, # Capacity
'p',4, # Percent (same as c)
'm',5, # Mount-point
'h',6, # Host
's',6 # Server (same as h)
$host = `hostname`;

while(defined($arg = shift))
if ($arg =~ s/^-//)
if ($arg eq 'f') # File to read for df output
die $usage unless(defined($file = shift));
elsif ($arg eq 'h') # Host name
die $usage unless(defined($host = shift));
elsif ($arg eq '-') # End argument processing
die $usage unless(defined($format = shift));
die $usage;
$format = $arg;

die $usage unless(defined($format));

@options = @ARGV;

if (defined($file))
open(IN,"<$file") &#0124; &#0124; die("$0: Cannot open \"$file\": $!\n");
$cmd = 'df '.join(' ',@options);
open(IN,"$cmd |") &#0124; &#0124; die("$0: Cannot fork: $!\n");

while(<IN> )

next if (/^File/); # Header

if ($cont ne '') # Continued lines
substr($_,0,0) = $cont;
$cont = '';
if (/^\S+\s*$/)
$cont = $_;

die "$0: Unexpected df output on line $.\n"
unless((@fields = split(/\s+/,$_)) == 6);
if ($fields[0] =~ /^(\S+):/)
$fields[4] =~ s/\%$//;


exit 0;

sub out
local($output,@f) = @_;

$output =~ s/\%(.)/($1 eq "%")?"%":&form($1,@f)/eg;
print $@ if $@;
print $output, "\n";

sub form
local($c,@f) = @_;

unless (defined($mapping{$c}))
die "$0: No mapping for \"\%$c\".\n";
Aaron Sherman I-Kinetics, Inc.
Systems Engineer "Open Systems Stepstones"
Voice: (617)661-8181 19 Bishop Allen Dr.
Fax: (617)661-8625 Cambridge, MA 02139
Pager: (508)545-0584

Thank you for your help.


Aug 25, 2000, 9:04 AM

Post #2 of 5 (1431 views)
Re: Used space on server [In reply to] Can't Post

Yes, it's possible to make it work from the browser, but you may be better off using something like ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

echo "Content-Type: text/plain"
echo ""


Aug 25, 2000, 9:48 AM

Post #3 of 5 (1431 views)
Re: Used space on server [In reply to] Can't Post

Sorry, What and how to make it work??


Aug 25, 2000, 11:14 AM

Post #4 of 5 (1431 views)
Re: Used space on server [In reply to] Can't Post

Put it in a file, upload it, make sure it's has permissions to be executed (typically chmod 755) and adhere's to whatever other guidelines need to be met to make it work at your provider (ie, Does it need a special extension? Does it need to be in a specific directory?).

After that, you just http://yourserver/path/to/script.


Aug 25, 2000, 9:37 PM

Post #5 of 5 (1431 views)
Re: Used space on server [In reply to] Can't Post

You talk about:

"Content-Type: text/plain"
echo ""/path/to/df



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives