LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2008, 07:48 AM   #1
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 188

Rep: Reputation: 30
Thumbs up Perl Run Script on all Files in folder on webserver


Hi,

I have a perl script that connect to a webserver and downloads a file and do some calculations with the file. Something like the following..

Code:
my $url = "http://localhost/test/file1.txt";
my $content = get $url;

while ($content =~ m/(\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/g) {
       # Each file has 6 columns, thats why i split it up
       #do calculations

}
All this is fine, but i want to change this so that the script will auto run on all files in the specified folder. So something like a 'ls' of the directory and then a loop to get the output from ls (or whatever) and run the calculations on the file one by one.. something like

Code:
ls into variable $filename        #not sure how to do this part

while ($filename) {
     my $url = "http://localhost/test/$filename";
     my $content = get $url;

     while ($content =~ m/(\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/g) {
       #do calculations
     }
}
Any suggestion how to get that first part right? i.e To list the files in the directory one by one into a variable of some sort and then get the files one by one?

Thanks for any help
 
Old 07-10-2008, 08:19 AM   #2
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 188

Original Poster
Rep: Reputation: 30
Hi,

Thanks, i figured something out.

Maybe theres a better way, but the following is good enough for me at the moment.

Code:
open(LS,"ls --format single-column /var/www/html/test |") || die "Failed: $!\n";
while ( <LS> ) {

        $filename = $_;
        print "Filename = $filename";
         
        my $url = "http://localhost/test/$filename";
        my $content = get $url;

        while ($content =~ m/(\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/g) {
          #do calculations
        }
}
 
Old 07-10-2008, 03:26 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
That works if the script is running on the same host as the web server. In that case, I recommend the perl function opendir(), followed by readdir(), closedir().
If you need to get a list of files on a remote web site, it must be configured co-operatively to provide index listings. The format of said listings can be variable, and you will also have to parse the filenames and other attributes out of the HTML code.
--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to run PHP files on my apache2 webserver kushalkoolwal Debian 7 10-01-2009 04:41 PM
Help create perl script for delete file/folder sportivo888 Linux - Newbie 5 12-05-2007 11:33 PM
how to run a shell script in the perl script sharad Linux - General 1 05-24-2006 03:23 AM
perl script help required to create users and changing the owner to pericular folder sridhar11 Programming 2 10-25-2005 02:16 PM
Uploading files to webserver in perl ? zulfilee Linux - Software 2 02-07-2005 11:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration