- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsI 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.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: TintinPosted on 2003-06-18 at 14:46:41ID: 8753118
To receive the pathname from a form, add
use CGI;
my $q = new CGI;
my $pathname = $q->param{'pathname'};
Where 'pathname' is whatever you called the input field on the form.
If it is going to take a long time to complete, I would definitely mail the results, otherwise you'll need to send output to the browser at regular intervals to ensure the connection doesn't timeout.