Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ZIP certain files in a directory using external OS commands

Sm1tje
Active Contributor
0 Kudos

Hi all,

I want to zip certain files in a certain directory using an external OS command in SM69.

For example:

in directory /abc/xyz I have the following files:

fileaaa

filebbb

fileabc

Now only the files starting with 'filea' have to be put into an archive file (zip file) with name archive1.zip

How to do this?

I already searched the forum and tried by using the unix command syntax, but I didn't succeed yet. So I guess I could use some help here. Please be precise in how to fill in all the parameters in SM69 since I have already tried a lot of combinations.

So please be so kind and answer my question by giving the exact commands and parameters per entry below:

1. Operating system command

2. Parameters for operating system command

3. Additional parameters (if necessary)

Thanks in advance.

Micky.

3 REPLIES 3

Former Member
0 Kudos

The procedure below works on any UNIX based application server as it uses only standard gzip and tar commands that are available on any UNIX system. If you want to use third party zip utilities installed on your UNIX system, to do zipping like Winzip does, then you need to tailor the script below accordingly.

You need to create a two liner shell script for this as this involves a series of UNIX command joined by pipe which require arguments.

I tested this on my machine and found it working

1. Create a shell script say ztar.sh with the following coding

#! /usr/bin/sh
find $1/* -prune -type f -name "$2" | xargs tar cf - | gzip -9c > $3

In the above $1 is file path and $2 is file name where you can pass filename mask like filea*.

find searches the files in the specified path (no recursive subdirectory search) and pipes the names to tar. If you want to search subdirectories also remove the -prune option.

tar simply concatenates the files together into a .tar file, which gzip will later zip into .gz file

gzip -9c: (9) is highest compression, (c) means to write to the standard output which we redirect to filename passed in argument $3

2. Put the script on a server path that is accessible to the SAP system user. Ensure that execute permission is set on this file. If required use chmod command like below

chmod 755 <path>/ztar.sh

3. Go to SM69 and create a command name like below

Command name = ZTAR
Operating system command = <path>/ztar.sh
Parameters for operating system command = ? ? ? 

You need to save the command, press f3 and save again. Otherwise the command doesn't really save

4. You can now execute the command in SE37 using function SXPG_COMMAND_EXECUTE. Ensure you have write permissions on the output paths and read/open permissions on all files that are to be zipped.

Upper/lower case = 'X'
COMMANDNAME = ZTAR
ADDITIONAL_PARAMETERS = <path of files to be zipped> filea* <output path>/output.tar.gz

or alternatively you can also test using SM49 transaction.

This means that the 3 additional parameters above substitute the three ? place holders mentioned in step 3

The above steps will tar all the files matching filea* and then gzip them.

Best regards,

Vishnu Tallapragada

0 Kudos

If you want to extract the files you need to unzip the output.tar.gz file using

gunzip output.tar.gz

then untar it using

tar xvf output.tar

PS: Since you used forward slashes, I assumed, your application server is UNIX )

Best regards,

Vishnu Tallapragada

0 Kudos

Hi Vishnu,

thanks for the reply. It was indeed a very helpful answer but unfortunately we are not allowed to go about this way. Has to do with authorization etc.

Micky.