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: Advanced:
Space still available

 



mmcw
User

Jul 19, 2000, 5:24 AM

Post #1 of 8 (1375 views)
Space still available Can't Post

Is there a way to check how much space there is still free
at my provider for my site.

For example:

At my provider I can use about 10 Mb of data.
I want to know if there is still room available
to upload more data.
When not I have to get an error!!

greetings Michel


Kanji
User / Moderator

Jul 18, 2000, 10:28 PM

Post #2 of 8 (1375 views)
Re: Space still available [In reply to] Can't Post

(no account) as your username looks a bit fishy. How are you running the code? Via CGI or from a shell?

Also, have you tried my guestimating script?


Kanji
User / Moderator

Jul 19, 2000, 6:36 AM

Post #3 of 8 (1375 views)
Re: Space still available [In reply to] Can't Post

You don't say what OS you're using but if your account is in a UNIX(ish) enviroment you should be able to use the command 'quota'.

If that isn't available, ask the server admin what he/she/they/it recommends, or employ a guestimate method in perl:

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

#!/usr/bin/perl -l

use File::Find;

my $quota = 1_048_576; # 1MB
my $directory = "/path/to/my/directory";

my $tally = 0;

find( \&tally, $directory );

sub tally {
$tally += -s $File::Find::name
}

if ( $tally > $quota ) {
print "Aiyee! You're ",
int( ( $tally - $quota ) / 1024 ),
"K over your quota!";
} else {
print "You've got ",
int( ( $quota - $tally ) / 1024 ),
"\K left.";
}</pre><HR></BLOCKQUOTE>


dws
Deleted

Jul 19, 2000, 8:36 AM

Post #4 of 8 (1375 views)
Re: Space still available [In reply to] Can't Post

Does your provider supply some type of "quota" program? If so, call it from Perl and parse out the numbers.


mmcw
User

Jul 19, 2000, 9:33 AM

Post #5 of 8 (1375 views)
Re: Space still available [In reply to] Can't Post

$test = `quota -v`; # backquotes
print "quota: $test<br><br>";

results is:
quota: Disk quotas for user (no account) (uid 320528): none

$test1 = `du`; # backquotes
print "quota: $test1<br><br>";

results in:
quota: 290 .

This is what they tell me (hypermart)
Your account is currently taking up 9879 kilobytes.
HyperMart allows you to use 20480 kilobytes.

???????????


mmcw
User

Jul 20, 2000, 10:50 AM

Post #6 of 8 (1375 views)
Re: Space still available [In reply to] Can't Post

Your guestimating script looks nice!!

I am running it from cgi. I put it into my script use!


mmcw
User

Jul 20, 2000, 10:23 PM

Post #7 of 8 (1375 views)
Re: Space still available [In reply to] Can't Post

Hello,

I can not use cron jobs!

I can not write C programs.
It would be nice if you vould help with that!
Is it possible to write such a script for me?

greetings Michel


dws
Deleted

Jul 21, 2000, 12:13 AM

Post #8 of 8 (1375 views)
Re: Space still available [In reply to] Can't Post

Oh. Right. Your ISPs web server is probably running CGIs at "nobody", so invoking quota from the CGI won't get you yours. Bummer.

Two alternatives:

1. Set up a cron job to periodically run quota and save the results in a .txt file that you can get at through the web server.

2. Write a short C program to exec quota for you, and arrange to run the resulting program setuid. Then exec the program from a CGI.


 
 


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

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