CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Cant run different perl script on same folder on server

 



tguile
New User

Aug 29, 2011, 9:13 PM

Post #1 of 4 (713 views)
Cant run different perl script on same folder on server Can't Post

I have a bunch of music files. I have a A folder and in that folder I have about 500 band folders with song files in each of the band folders. I have a perl script that I execute from the browser to make a html file of all the bands in the A folder that makes links to the band folders. The path of that is to the A folder. I also have a script that has its path also to the A folder but it makes html links of all the bands songs and places that file in the band folder. All the folders are on the server. I just execute the script for the band link files once and it makes index linj files for all 500 bands. My problem is when I use one script on the A folder the other one wont work. Once I make a band html file and cant do the song html file and vice versa. Anyone know why and what I do to fix it? Thanks


wickedxter
User

Aug 30, 2011, 12:41 PM

Post #2 of 4 (674 views)
Re: [tguile] Cant run different perl script on same folder on server [In reply to] Can't Post

Where are you scripts located? cgi-bin folder?

is your server limited to execute scripts only in cgi-bin or any where?

if server on a *nix did u chmod it right?

How does the script work like when you click the link? does it download the file or is a media player attached to play them?

Do you get an ERROR message? if so plz show the error message.

Can we see the code?


tguile
New User

Aug 31, 2011, 8:43 AM

Post #3 of 4 (666 views)
Re: [wickedxter] Cant run different perl script on same folder on server [In reply to] Can't Post

The scripts are located in my html folder on the server. Not the cgi folder. It works from there. I just put the url to the script in my browser and it runs.

I dont know what *nix is but I do chmod the script and folders. Im not really sure about permissions. I guess it is me, the group on the server and everyone else I just make it all read, write and execute.

For how it works here is a link to a page: http://www.guitarstars.biz/guitarpro/A/

These are all band folders in the A folder. Instead of me writing each link by hand I made a script that I just execute once and it makes a index html page with all the links. Here is that script:

#!/usr/bin/perl

$band = Z;

opendir(LINKS, "/path/path/path/path/html/guitarpro/$band");
@links = readdir(LINKS);
closedir(LINKS);
open(HTML, ">/path/path/path/path/html/guitarpro/$band/index.html");

shift(@links);
shift(@links);

print HTML "<html>\n";
print HTML "<head>\n";
print HTML "<title>Index of $band</title>\n";
print HTML "</head>\n";
print HTML "<body>\n";
print HTML "<h1>Index of $band</h1>\n";
print HTML "<ul>\n";

foreach $filename (@links) {

print HTML "<li><a href=\"$filename\">$filename</a></li>\n";

}

print HTML "</ul>\n";
print HTML "</body>\n";
print HTML "</html>\n";

close(HTML);

This will make links on a index.html page to all files or folders in a folder.

Well, I have like 6500 different bands and 27 0-9 to Z folders. So I would have to execute this over 6500 times to make all the links to the bands and links to the bands songs. So I made a script that I pointed the path to the A or B Or C folder etc... And it would print links to all the bands songs. An example is the A folder that I gave the link to above. I point the path to that folder and it makes a index.html page with all the links to the songs of that band and puts that index.html file in that bands folder. It loops its way through all the band folders and does the same.

Here is that script:

#!/usr/bin/perl

@bands;
$bandsname;
@links;
$filename;

opendir(BANDS, "/path/path/path/path/html/guitarpro/Z");
@bands = readdir(BANDS);
closedir(BANDS);

shift(@bands);
shift(@bands);


foreach $bandsname (@bands) {


opendir(LINKS, "/path/path/path/path/html/guitarpro/Z/$bandsname");
@links = readdir(LINKS);
closedir(LINKS);
open(HTML, ">/path/path/path/path/html/guitarpro/Z/$bandsname/index.html");

shift(@links);
shift(@links);

print HTML "<html>\n";
print HTML "<head>\n";
print HTML "<title>Index of $bandsname</title>\n";
print HTML "</head>\n";
print HTML "<body>\n";
print HTML "<h1>Index of $bandsname</h1>\n";
print HTML "<ul>\n";

foreach $filename (@links) {

print HTML "<li><a href=\"$filename\">$filename</a></li>\n";

}


print HTML "</ul>\n";
print HTML "</body>\n";
print HTML "</html>\n";

close(HTML);

}

So. now instead of me executing the first script on each band folder 6500 times. I execute the second script on the A or B folder and it makes all the song links. I only execute it like 27 times and I make about 50000 song links. The first script I used to make links to all the band folders the second I used to make links to all the bands songs. They both have paths to the A or B or C etc... folder. The scripts have different names.

Once I used one on the A folder though the second one wouldnt work. It seemed that maybe the server for security or something would only let 1 script have access to execute. So I just put both of thhese scripts in one script and it made the song links and and the links tp the bands.

I solved my problem but why do you think it wouldnt let me only execute the one script and not another and how do you solve that?


wickedxter
User

Aug 31, 2011, 9:50 AM

Post #4 of 4 (662 views)
Re: [tguile] Cant run different perl script on same folder on server [In reply to] Can't Post

When reading directories you need to skip the " . "" and " .. " or they will showup when you loop threw them.

IMO i think it would make it more effective if you make both scripts in to one and you can either make it fully automated needing no input from you or you can setup to use the query from the web broswer for input ie. page.html?letter=A

That would also limit the annoyance of have to run two seperate scripts.

also as a design note it might be better to read each folder and index it at a time rather then slurping the whole directory tree in. It could over load the server given it exceeds the memory of the server and plus you could be hogging the server.


also you need to use the strict module and learn to scope variables with my it will help down the road if the script gets bigger or future projects.


(This post was edited by wickedxter on Aug 31, 2011, 9:53 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives