KSH Shell script not zipping up files

Asked
Active3 hr before
Viewed126 times

9 Answers

90%

@meuh I removed the - in the set -A FILE_LIST -, here are the results of the error logs from our server. What does this mean because the txt files that I selected to zip and download to my desktop are still not saving to the zip folder. Here are the results below: , 1 The exec format error suggests that the zip program found in the PATH is probably a binary compiled for Solaris. If you type command -v zip it should print something like /usr/bin/zip if it has been installed from a package. – meuh Oct 11 '18 at 14:51 ,Here is the code below that zips up the files. Any idea why this Korn shell script works in development but not in production? ,I have a Korn shell script that is supposed to zip up files and it is not working properly in development. The same exact script works in production which is strange. We recently upgraded our Solaris Unix box to a Linux box in the development environment. So I am assuming that this may be the cause of the script not executing.

Here is the code below that zips up the files. Any idea why this Korn shell script works in development but not in production?

#!/bin/ksh

#
# Utility to zip up files in the configuration_aerodynamic_properties area.
# Script takes two arguments the directory and the file list.
# The file list is tab seperated.
# This script returns the zip file.
#
# $Log: vmdb_zip_files.sh, v $
# Revision 1.4 2014 / 10 / 21 19: 53: 31 wmorris1
# ASR 13563 - Change incorrect mime type text / text to text / plain.
#
# Revision 1.3 2012 / 04 / 30 18: 46: 03 wmorris1
# ASR 12774 - Fix SSL and IE issue found after going to SSL.
#
# Revision 1.2 2004 / 11 / 11 12: 49: 33 bmorris
# ASR 55414 - removed UNIX groups
for zipped file.
#
# Revision 1.1 2004 / 10 / 18 20: 10: 32 bmorris
# Initial revision
#
#set - x

function error_message {
   echo "Content-Type: text/plain;"
   echo "Content-Disposition: attachment; filename=\"download_error.txt\";"
   COMMAND = "unix2dos"
   echo ""
   echo "$(${COMMAND}  <<-EOF
   Error: $1

   EOF
)
"
}
if ["$#" - lt 2];
then
error_message "Insufficient arguments to $(basename $0)!"
return 1
fi
CONTENT = "application/x-zip-compressed"
# Parse the directory path.
# Internal Field Sep(IFS) empty, cause spaces in file names, directories are important
IFS = ""
FULL_DIRECTORY_PATH = $(echo "${1}" | tr - d '~\\')
# File lists are seperated by tabs, parse them
IFS = $(echo "\t")
set - A FILE_LIST - $ {
   2
}
# Make each of the file parameters in the file list protected.
let count = 0
while (($count < $ {
      #FILE_LIST[ * ]
   }));
do
   FILE_LIST[count] = "\"${FILE_LIST[count]}\""
let count = "count +1"
done
# Reset the IFS to the
default.
IFS = $(echo " \n\t")
if [
   [-n $3]
];
then
WEB_FILENAME = "$3"
fi
# Don 't let the user download stuff.
if [
   ["${1}" = * ..*]
] || [
   ["${1}" = * ~ * ]
] || [
   ["${2}" = * ..*]
] || [
   ["${2}" = * ~ * ]
];
then
error_message "Path ${1}/${2} violates security."
return 1
elif[[!-f $ {
   FULL_DIRECTORY_PATH
}]] && [
   [!-d $ {
      FULL_DIRECTORY_PATH
   }]
];
then
error_message "${FULL_FILE_PATH} does not exist or is not regular."
return 1
elif[[!-r $ {
   FULL_DIRECTORY_PATH
}]];
then
error_message "${FULL_FILE_PATH} is not readable from the web."
return 1
fi
# Zip up the f
COMMAND = "cd \"${FULL_DIRECTORY_PATH}\"; zip -rX - ${FILE_LIST[*]}"
echo "Content-Type: ${CONTENT};"
if [
   [-z $HTTP_USER_AGENT || $HTTP_USER_AGENT != * MSIE * ]
];
then
# IE Can 't handle ssl and zip files
echo "Pragma:no-cache"
fi
echo ""
eval "$COMMAND"
load more v
88%

Here is the shell script that is being called below:, Questions ,Asking for help, clarification, or responding to other answers., 1 I used /usr/bin/zip in my script in place of the zip command and that fixed it. I will speak to the site admin about this issue, thank you for the help. – Chris M Oct 12 '18 at 17:51

The command type zip is telling you that it will not run /usr/bin/zip, therefore the output of file /usr/bin/zip is irrelevant. It is using the one in /oraloc/app/product/11.2.0/client_1/bin/, this is suspicious.

type zip

The command type zip is telling you that it will not run /usr/bin/zip, therefore the output of file /usr/bin/zip is irrelevant. It is using the one in /oraloc/app/product/11.2.0/client_1/bin/, this is suspicious.

/usr/bin / zip

The command type zip is telling you that it will not run /usr/bin/zip, therefore the output of file /usr/bin/zip is irrelevant. It is using the one in /oraloc/app/product/11.2.0/client_1/bin/, this is suspicious.

file / usr / bin / zip

The command type zip is telling you that it will not run /usr/bin/zip, therefore the output of file /usr/bin/zip is irrelevant. It is using the one in /oraloc/app/product/11.2.0/client_1/bin/, this is suspicious.

/oraloc/app / product / 11.2 .0 / client_1 / bin /
load more v
72%

unzip <filename>
   gzip -d <filename>
load more v
65%

The zip program is used to package and compress files.,Scanning and reading files,The stream can also be saved to a file and unzip used.,If a file list is specified as [email protected], zip takes the list of input files from standard input instead of from the command line. For example,


zip - b / tmp stuff *
load more v
75%

What!? How is my simple list not a "valid file structure"? Back to the manual for more information, and I take a closer look at:,-@ file lists. If a file list is specified as -@ [Not on MacOS], zip takes the list of input files from standard input instead of from the command line. For example,,Connect and share knowledge within a single location that is structured and easy to search.,The manual isn't referring to a literal list as in a file, but rather literally to listing the files out on the console.

Firstly using the file list we created, we can read out the list with cat and redirect the output with a pipe as standard input to zip:

cat zip.lst | zip - @ files.zip

adding: file1.txt(stored 0 % )
adding: file2.txt(stored 0 % )
adding: file3.txt(stored 0 % )
adding: file.jpg(stored 0 % )
adding: test.jpg(stored 0 % )

Seeing that adding: ... for each file is certainly a good sign, but we've had our hopes up before, so let's just confirm:

unzip - l files.zip

Archive: files.zip
Length Date Time Name
-- -- -- -- - -- -- -- -- -- -- -- - -- --
0 2016 - 05 - 24 14: 54 file1.txt
0 2016 - 05 - 24 14: 54 file2.txt
0 2016 - 05 - 24 14: 54 file3.txt
0 2016 - 05 - 24 15: 00 file.jpg
0 2016 - 05 - 24 14: 59 test.jpg
   -- -- -- -- - -- -- -- -
   0 5 files

SWEET! But who wants to create a onetime-use list anyway? That's an awful round-about way of solving this particular scenario. It would be better to get a list from ls and pipe that to zip:

ls | zip - @ files.zip

adding: file1.txt(stored 0 % )
adding: file2.txt(stored 0 % )
adding: file3.txt(stored 0 % )
adding: file.jpg(stored 0 % )
adding: test.jpg(stored 0 % )

Fabulous! Now let's create filters with the awesome power of grep to just zip up the jpg's for instance:

ls | grep.jpg | zip - @ images.zip

adding: file.jpg(stored 0 % )
adding: test.jpg(stored 0 % )

Or just files beginning with "file"

ls | grep file. | zip - @ files.zip

adding: file1.txt(stored 0 % )
adding: file2.txt(stored 0 % )
adding: file3.txt(stored 0 % )
adding: file.jpg(stored 0 % )
load more v
40%

How to create a file in Linux using the bash shell terminal,Fig.02: How to unzip a zip file from the Terminal using unzip command,Fig.01: How to use a tar command to unzip a file on Linux/Unix-like terminal,How to extract tar.xz files in Linux and unzip all files

Use unzip command to unzip a zip file

The syntax is:
unzip {file.zip}
Use the following syntax if you want to extract/unzip to a particular destination directory:
unzip -d /dest/directory/ {file.zip}
For example, unzip a zip file named master.zip using zip command:
unzip master.zip
To unzip a zip file named master.zip using zip command to a /tmp/data/ directory:
unzip -d /tmp/data/ master.zip
Sample session:

unzip {
   file.zip
}

Use unzip command to unzip a zip file

The syntax is:
unzip {file.zip}
Use the following syntax if you want to extract/unzip to a particular destination directory:
unzip -d /dest/directory/ {file.zip}
For example, unzip a zip file named master.zip using zip command:
unzip master.zip
To unzip a zip file named master.zip using zip command to a /tmp/data/ directory:
unzip -d /tmp/data/ master.zip
Sample session:

unzip - d / dest / directory / {
   file.zip
}

Use unzip command to unzip a zip file

The syntax is:
unzip {file.zip}
Use the following syntax if you want to extract/unzip to a particular destination directory:
unzip -d /dest/directory/ {file.zip}
For example, unzip a zip file named master.zip using zip command:
unzip master.zip
To unzip a zip file named master.zip using zip command to a /tmp/data/ directory:
unzip -d /tmp/data/ master.zip
Sample session:

unzip master.zip

Use unzip command to unzip a zip file

The syntax is:
unzip {file.zip}
Use the following syntax if you want to extract/unzip to a particular destination directory:
unzip -d /dest/directory/ {file.zip}
For example, unzip a zip file named master.zip using zip command:
unzip master.zip
To unzip a zip file named master.zip using zip command to a /tmp/data/ directory:
unzip -d /tmp/data/ master.zip
Sample session:

unzip - d / tmp / data / master.zip
load more v
22%

Separate names with a comma., Operating System

 unzip <filename>
    gzip -d <filename>
load more v
60%

unzip - list, test and extract compressed files in a ZIP archive ,invalid options were specified on the command line. ,Archives read from standard input are not yet supported, except with funzip (and then only the first member of the archive can be extracted). ,the end of the ZIP archive was encountered prematurely.

"*.c"
matches "foo.c"
but not "mydir/foo.c"
"**.c"
matches both "foo.c"
and "mydir/foo.c"
"*/*.c"
matches "bar/foo.c"
but not "baz/bar/foo.c"
"??*/*"
matches "ab/foo"
and "abc/foo"
but not "a/foo"
or "a/b/foo"
load more v
48%

zip is used to compress the files to reduce file size and also used as file package utility. zip is available in many operating systems like unix, linux, windows etc.,If you have a limited bandwidth between two servers and want to transfer the files faster, then zip the files and transfer.,ZIP is a compression and file packaging utility for Unix. Each file is stored in single .zip {.zip-filename} file with the extension .zip.,After updating hello5.c from myfile.zip file, the files can be restored with unzip command

Syntax :

zip[options] zipfile files_list
load more v

Other "undefined-undefined" queries related to "KSH Shell script not zipping up files"