Solved

zip from perl script

Posted on 2000-05-08
5
474 Views
Last Modified: 2008-02-01
Newbie has the following question:

I'm using the zip -command with the 'system' directive in a perl script.
(e.g. system (zip /home/test/test.zip /home/data/source1.txt /home/data/source2.txt);)

The script is run by the webserver (User:wwwrun(nogroup))


The source files come from a script generated filelist-Variable.
Wildcards are useless for my needs.

I've got more than 100 source files, all resident in the same directory.

1. Is there a way to use the same path for all source files
instead of using the whole path for every source-file entry ?

2. How many source files (how many lines of source files) does the zip-routine accept
for input ?

zip offers the possibilty to specify the file list with "-@"
I tried to make an include.list and an exclude.list
Nothing worked ? Any hints, help ?

Thanks in advance

Mfuerlinger
0
Comment
Question by:mfuerlinger
  • 2
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
1. how about doing a chdir to the directory
2. may be limited by your command shell (you might try using a multi-argument system call to bypass the command shell)
in quotes, qq"-@" may need \
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
if you dont mind use a PERL module for zip'ing the files, you can use the Archive::Zip module.


The Archive::Zip module  allows a Perl program to create, manipulate,
read, and write Zip archive files.

Zip archives can be created, or you can read from existing zip files.
Once created, they can be written to files, streams, or strings.

Members can be added, removed, extracted, replaced, rearranged, and
enumerated.  They can also be renamed or have their dates, comments, or
other attributes queried or modified.  Their data can be compressed or
uncompressed as needed.  Members can be created from members in existing
Zip files, or from existing directories, files, or strings.

This module uses the Compress::Zlib library to read and write the
compressed streams inside the files.

Here is a small example.

#!/bin/perl -w
# Creates a zip file, adding the given directories and files.
# Usage:
#      perl zip.pl zipfile.zip file [...]

use strict;
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);

die "usage: $0 zipfile.zip\n"
      if (scalar(@ARGV) < 2);

my $zipName = shift(@ARGV);
my $zip = Archive::Zip->new();

foreach my $memberName (@ARGV)
{
      my $member = -d $memberName
            ? $zip->addDirectory( $memberName )
            : $zip->addFile( $memberName );
      warn "Can't make member $memberName\n" if ! $member;
}

my $status = $zip->writeToFileNamed($zipName);
exit $status;


0
 
LVL 1

Author Comment

by:mfuerlinger
Comment Utility
I tried both of your suggestions ... and found another solution which fits my needs:

for (@filelist)     {
     $zipfile = "$path/$_\n";
     $zipcmd = "zip -j -D -X /home/test/ $zipfile\n";
system($zipcmd);
                         }

To finish this question I gonna give the points to the one who replies FIRST to my comment.

ENJOY

Mathias
0
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
Comment Utility
glad to know that you were able to find a working solution!!

0
 
LVL 1

Author Comment

by:mfuerlinger
Comment Utility
Thanks for your time :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Extract multiple value with delimiters from a string 4 166
perl script 4 93
crawling gofundme 4 103
iSeries PERL Scripts 7 126
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now