I have written a program in perl that, when given a server path, will report the size of every folder 1 level below the given path. The use for this is in determining the size of user home drives on a network. What I am trying to do now is run that script through a cgi/web interface. What I envision is that a user will come to a website where they will enter the path to the directory they want to search into a text box ( \\theserver\share ). What I can't figure out is how to pass this to my perl script as an input parameter. I should note that I only need it to accept 1 input when it's executed.
This leads to somewhat of another question. This script could, in reality, take a great deal of time to finish (30+ min.) depending on the size of the directories. Is there a way to keep the script running on the server, even after the user has closed their browser? I am planning on adding functionality to where the script will email the results to the user.
Here is what I have now. Keep in mind that I have not modified it at all to be run on a web server. As it is shown below, it accepts input (server names) from a file and outputs the results to a file.
==========================
======
use File::Find;
use strict;
my ($dir, @parts, $error);
open(IN, "< input.csv") or die("Couldn't open input.csv\n");
open(OUT, "> output.csv") or die("Couldn't open output.csv\n");
#Separates input by line
chomp ( @parts = <IN> );
#Prints headings for output
print OUT "Path,MB,Errors\n";
use File::Find;
use File::Spec;
use strict;
my $cur = File::Spec->curdir;
my $up = File::Spec->updir;
my $dirtot;
#Displays total for subdirectories
foreach my $start (@parts) {
my @dirs = &find_subdirs($start);
foreach my $dir (@dirs) {
print "Walking $dir\n";
my $total = 0;
find sub { $total += -s }, $dir;
$dirtot = $dirtot + $total; #Used for determining total directory size
$total = ($total / 1024) / 1024; #Converts to MB
$total = sprintf("%0.2f", $total); #Formats output to 2 decimals
print OUT "$dir,$total,$!\n";
}
print STDERR "$start: No subdirectories\n" unless @dirs;
}
sub find_subdirs {
my $start = shift;
unless(opendir(D, $start)) {
warn "$start: $!\n";
next;
}
my @dirs =
map {
-d "$start/$_" &&
!-l "$start/$_" &&
$_ ne $cur && $_ ne $up
? "$start/$_" : ()
}
readdir(D);
closedir(D);
@dirs;
}
close(OUT);
==========================
==========
==========
==
I'm really not sure where to go from here. I haven't been working with Perl for a real long time, and I am brand new to CGI. I appreciate anyone's comments.