Gossamer Forum
Home : General : Perl Programming :

script to show amount of space used

Quote Reply
script to show amount of space used
Hello,

I am looking for a script that when placed in a directory gets the amout of total space used by all files in the directory and subdirectories+files. I would like to be able to call this via ssi to display anywhere else on the site.

Any ideas?

Thanks
Quote Reply
Re: [socrates] script to show amount of space used In reply to
Hi,

How about:

Code:
sub space_used {
require File::Find;
my $dir = shift;
my $size = 0;
find ($dir, sub { $size += -s $File::Find::name; });
return $size;
}


Cheers.

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] script to show amount of space used In reply to
Alex, thanks but I am getting an error - undefined sub &main::find called for this line:

find ($dir, sub { $size += -s $File::Find::name; });

I checked the server and the module File::Find is installed on the server.
Quote Reply
Re: [socrates] script to show amount of space used In reply to
Oops, going to have to change require File::Find to use File::Find.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] script to show amount of space used In reply to
He.. now a new error

can't stat CODE (0x80b6d28) : No such file or directory

thanks
Quote Reply
Re: [socrates] script to show amount of space used In reply to
Oops... here use this:

Code:
sub space_used {
require File::Find;
my $dir = shift;
my $size = 0;
File::Find::find (sub { $size += -s $File::Find::name; }, $dir);
return $size;
}

that should work.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] script to show amount of space used In reply to
Hi Alex,

Still getting that error:

can't stat : No such file or directory



#!/usr/bin/perl

sub space_used {

use File::Find;

my $dir = shift;

my $size = 0;

File::Find::find (sub { $size += -s $File::Find::name; }, $dir);

return $size;

print "$size heeeeeeelllllllllllllooooooooo\n";

}

&space_used;

exit;




Thanks

Last edited by:

socrates: Apr 4, 2002, 11:36 AM
Quote Reply
Re: [socrates] script to show amount of space used In reply to
You have my $dir = shift but aren't telling the sub which directory to use.

Either do:

space_used('/path/to/dir');

Or manually enter the path as $dir's value.

You don't need exit either.

Last edited by:

Paul: Apr 4, 2002, 11:41 AM
Quote Reply
Re: [socrates] script to show amount of space used In reply to
The code Alex provided was not a standalone script - just a subroutine (function) to incorporate into an existing script. As such, it expects $dir to be passed to space_used (via my $dir = shift; line). So you need to define $dir - either by calling SUB and passing directory, or by defining $dir in the SUB.



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] script to show amount of space used In reply to
You know the saying...

"great minds..." Wink
Quote Reply
Re: [Paul] script to show amount of space used In reply to
Hey Paul:

Yep, although some people define my mind more as a grating mind Wink



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] script to show amount of space used In reply to
Well actually I did try to put the path for the directory before i posted my message. It gave me the same error. I will have to try again.

thanks
Quote Reply
Re: [socrates] script to show amount of space used In reply to
So Paul,

Who is the great mind, mate?

Is it you, Alex, or me?

What is this in reference to and what does it have to with my question?



Quote:


You know the saying...

"great minds..." Wink

Last edited by:

socrates: Apr 4, 2002, 1:00 PM
Quote Reply
Re: [socrates] script to show amount of space used In reply to
Quote:
What is this in reference to and what does it have to with my question?

Umm..it was related to the fact that dan and I posted almost the exact same answer at the same time Crazy

Last edited by:

Paul: Apr 4, 2002, 1:34 PM
Quote Reply
Re: [Paul] script to show amount of space used In reply to
I see! Crazy