Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have the following script in my cgi-bin to unzip a file named "-ubl.zip" to a directory 'LeagueSite'. HERE IS THE SCRIPT ON MY SPACE:
#!/usr/bin/perl use strict; use CGI::Carp qw(fatalsToBrowser); my $Verzeichnis = "/home/wwwubl/public_html/LeagueSite/"; my $zipfile = $Verzeichnis . "_ubl.zip"; if (-e $zipfile) { $r = system("unzip -o -q -C $zipfile -d $Verzeichnis"); if ($r==0) { print "Success!\n"; unlink($zipfile); } else { print "Error " . $r . "\n"; } }
When I call this script, I get the following error: Software error: Global symbol "$r" requires explicit package name at unzipfiles.cgi line 10. Global symbol "$r" requires explicit package name at unzipfiles.cgi line 11. Global symbol "$r" requires explicit package name at unzipfiles.cgi line 16. Execution of unzipfiles.cgi aborted due to compilation errors. What do I have configured incorrectly in this script to make it do what I want it to do. This zipped file is put up three times weekly and is 3Megs in size. It is always named _ubl.zip and it always needs to unzip to my LeagueSite directory. My email is volunteer1967@hotmail.com and I will check back on this site as well. Thanks in advance, Mark Cooley

Replies are listed 'Best First'.
Re: Script to unzip a zip file on the server......
by sschneid (Deacon) on Mar 27, 2003 at 17:18 UTC
    You're using strict, but haven't defined the scope of $r. Try:
    my $r = system("unzip -o -q -C $zipfile -d $Verzeichnis");
    -s.
      OK, I changed that line and now I get: Error 500 and Error 404 Could that be b/c I don't have a zip file on the space at the moment? I do have it set up to unzip to the LeagueSite directory, don't I?
        Error 404 means "file not found": ie the web server couldn't find the script you were trying to get.

        Error 500 means "internal server error": usually an error in your script. Look in your server error logs to find out the specific error log, or try this in your script: use CGI::Carp qw(fatalsToBrowser);

        andramoiennepemousapolutropon

Re: Script to unzip a zip file on the server......
by ScooterQ (Pilgrim) on Mar 27, 2003 at 20:20 UTC
    My first though is that your problem might be path-related. I'd suggest providing the full path to the unzip command. It's quite possible that the web server doesn't have unzip in its path.
    I have a very similar script that I run on a machine at home. I'll check it this evening and add to this comment if I find anything else that might be helpful for you.
      The path /home/wwubl/public_html/LeagueSite is the path to where I want it to unzip. I'm not sure I follow you.......this is the only path entered in the script that I can find. If you have a script that will do what I want and I can use it after its personalized, I'd appreciate it.
        By path, ScooterQ means the PATH environment variable in Unix, not the path where you want the zip to be extracted to. Shells will search the PATH variable for executables and other files. If an executable isn't in one of the directories specified by PATH, then you need to use its full path (such as /usr/bin/unzip instead of unzip) to run it.

        Update: Run this as a CGI script to see the what the PATH variable for CGI scripts is set to:

        #!/usr/bin/perl -w use strict; print "Content-type: text/html\n\n", `echo \$PATH`.
        (This is untested code, but it should work unless I've made a really stupid mistake. Also, showing the PATH could be a security risk, so after you've run it, be sure to make it non-accessible by others.)
Re: Script to unzip a zip file on the server......
by The Mad Hatter (Priest) on Mar 28, 2003 at 01:23 UTC
    I just noticed that you never sent the Content-type header. You need to do this before printing anything for the browser to interpret. You can either use CGI to do this, or for such a simple script, just do a print "Content-type: text/html\n\n"; before any other print statements.