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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



mmcw
User

Aug 25, 2000, 2:52 AM

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

Hello,

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: feenix.metronet.com comp.lang.perl:5272
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.ecn.bgu.edu!usenet.ins.cwru.edu!howland.reston.ans.net!math.ohio-state.edu!cs.utexas.edu!uunet!fmrco!fmrco!asherman
From: asherman@fmrco.com (Aaron Sherman)
Subject: Re: determining available disk space
In-Reply-To: jeff@rtr.com's message of Fri, 20 Aug 1993 11:29:43 GMT
Message-ID: <ASHERMAN.93Aug24143015@uboat.fmrco.com>
Sender: news@fmrco.uucp
Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
References: <1993Aug20.112943.26545@rtr.com>
Date: Tue, 24 Aug 1993 19:30:15 GMT
Lines: 157


>>>>> jeff@rtr.com (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".


-AJS

#!/usr/local/bin/perl
#
# 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`;
chop($host);

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));
last;
}
else
{
die $usage;
}
}
else
{
$format = $arg;
last;
}
}

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

@options = @ARGV;

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

while(<IN> )
{
chop;

next if (/^File/); # Header

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

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

&out($format,@fields);
}

exit 0;

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

$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";
}
$f[$mapping{$c}];
}
__END__
--
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 asherman@i-kinetics.com


Thank you for your help.



Kanji
User

Aug 25, 2000, 9:04 AM

Post #2 of 5 (774 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>

#!/bin/sh
echo "Content-Type: text/plain"
echo ""
/path/to/df</pre><HR></BLOCKQUOTE>


mmcw
User

Aug 25, 2000, 9:48 AM

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

Sorry, What and how to make it work??


Kanji
User

Aug 25, 2000, 11:14 AM

Post #4 of 5 (774 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.


mmcw
User

Aug 25, 2000, 9:37 PM

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

You talk about:

#!/bin/shecho
"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