[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

Passing parameters to Perl Script

Asked by concept99 in CGI Scripting

Tags: perl, parameters, script, passing

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.
 
Related Solutions
Keywords: Passing parameters to Perl Script
 
Loading Advertisement...
 
[+][-]06/18/03 02:46 PM, ID: 8753118Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: CGI Scripting
Tags: perl, parameters, script, passing
Sign Up Now!
Solution Provided By: Tintin
Participating Experts: 1
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-92