Hugeusrealus has asked for the wisdom of the Perl Monks concerning the following question:

I received a file from a friend (a really fantastic perl programmer) for checking disc space usage of web sites on a server. I continuously slam him with a barrage of questions……. So I am trying rather unsuccessfully to find my own answers now. The script should check for disc space usage in sites which I place directories for under the my @sites= list on line 14. This all looks pretty simple to me and I believe I understand it……. Except on thing. The reason it doesn’t work seems to be line 8 “if ($pass ne 'Tn9SG0s') { exit; }” I understand that the code says if you receive a pass not equal to 'Tn9SG0s' then exit. But what I don’t understand is what is 'Tn9SG0s'? Right now the script prints line 2 and exits. Any thoughts or ideas would be most appreciated. THANKS! Here it is enlighten me please!
#!/usr/bin/perl print "Content-Type: text/html\n\n"; use CGI; my $query = new CGI; my $pass = $query->param('pass'); if ($pass ne 'Tn9SG0s') { exit; } $path = "/home/httpd/$site/html/"; use File::Find; my @sites = ("xyz-site/xyz-site-directory", "xyz-site2/xyz-site-directory2" ); push(@sites, '/home/tomato/', #put any other directories in here ); foreach my $site (@sites) { $sizeb = 0; $path = "/home/httpd/$site" if $site !~ m!^/!; $path = "$site" if $site =~ m!^/!; #$path = "/home/stanley/"; $file = 0; &find ( sub { $sizeb += -s }, "$path"); &find ( sub { $file += 1 }, "$path"); my $sizekb = int ($sizeb / 1024); my $sizemb = int ($sizekb / 1024); print qq(<h4> $site </h4>); print " Files $file <br>"; print " bytes $sizeb <br>"; print "Kbytes $sizekb <br>"; print " mbytes $sizemb <br>"; }
PS I have tried to comment out line line 6 my $pass = $query->param('pass'); but then the script just hangs.... So what is wrong with my new CGI (line 5).

Replies are listed 'Best First'.
You're kidding, right?
by tmoertel (Chaplain) on Sep 17, 2004 at 05:32 UTC
Re: Disc Space checking
by jZed (Prior) on Sep 17, 2004 at 05:36 UTC
    $pass is your password. If you do not enter the string $pass expects, the script will exit. If your script is located in the foo directory and called bar.cgi, you need to use a query string something like http://yoursite/foo/bar.cgi?pass=Tn9SG0s except, now that everone on this site knows that is your password, you should change it to something else in the script and use that to call the script.

    I would also suggest that your friend is not as great a programmer as you might think because the script does not use warnings or strict and neglects to check if there's anything in the pass parameter at all.

      humbely thank you
Re: Disc Space checking
by PodMaster (Abbot) on Sep 17, 2004 at 05:31 UTC
    if( $pass ne 'only those know what pass is supposed to be can see +this stuff'){ exit; }
    Its your friends version of password protection.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Disc Space checking
by tachyon (Chancellor) on Sep 17, 2004 at 05:47 UTC

    The script was designed to be called as a CGI script. It could be called by a form or simply by typing in http://yoursite.com/cgi-bin/scriptname.pl?pass=Tn9SG0s You can run it from the command line using ./script.pl pass=Tn9SG0s.

    Anyway seeing you are on a *nix you could probably just do:

    du -hs /home/*

    For a bit more pizzaz try:

    du -hs `du -bs /home/* 2>/dev/null |sort -nrk 1|head -20|cut -f 2`

    Which will give you the sorted top twenty dirs (in /home in this example) with nice human readable sizes.

    cheers

    tachyon

      Ew, that hits the tree twice :(

      On a big directory you'd probably want to put du's output in RAM and do the postprocessing there...

        Yes, but it only hits 20 indodes the second time around :-)

        cheers

        tachyon