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.
The pic below is shows the file list. The user will select a checkbox for the files they want to download and then they click the zip and download link and it should zip up those selected files and save it to your desktop. Unfortunately the zip folder is empty. Any ideas what the problem may be?
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"
@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:
Hello Chris: cat vmdb_zip_files_8862.err
+ [ 3 -lt 2 ]
+ CONTENT=application/x-zip-compressed
+ IFS=''
+ tr -d '~\\'
+ echo /isweb/www/ss/issapt/vmdb/data_downloads/power_export
+ FULL_DIRECTORY_PATH=/isweb/www/ss/issapt/vmdb/data_downloads/power_export
+ printf '\t'
+ IFS=$'\t'
+ set -A FILE_LIST flight_dependent_heater_data_443949.txt flight_dependent_data_443949.txt
+ let count=0
+ (( 0 < 2 ))
+ FILE_LIST[0]='"flight_dependent_heater_data_443949.txt"'
+ let count='count +1'
+ (( 1 < 2 ))
+ FILE_LIST[1]='"flight_dependent_data_443949.txt"'
+ let count='count +1'
+ (( 2 < 2 ))
+ echo ' \n\t'
+ IFS=' \n\t'
+ [[ -n power_export.zip ]]
+ WEB_FILENAME=power_export.zip
+ [[ /isweb/www/ss/issapt/vmdb/data_downloads/power_export == *..* ]]
+ [[ /isweb/www/ss/issapt/vmdb/data_downloads/power_export == *~* ]]
+ [[ $'flight_dependent_heater_data_443949.txt\tflight_dependent_data_443949.txt' == *..* ]]
+ [[ $'flight_dependent_heater_data_443949.txt\tflight_dependent_data_443949.txt' == *~* ]]
+ [[ ! -f /isweb/www/ss/issapt/vmdb/data_downloads/power_export ]]
+ [[ ! -d /isweb/www/ss/issapt/vmdb/data_downloads/power_export ]]
+ [[ ! -r /isweb/www/ss/issapt/vmdb/data_downloads/power_export ]]
+ COMMAND='cd "/isweb/www/ss/issapt/vmdb/data_downloads/power_export"; zip -rX - "flight_dependent_heater_data_443949.txt" "flight_dependent_data_443949.txt"'
+ echo 'Content-Type: application/x-zip-compressed;'
+ [[ -z 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko' ]]
+ [[ 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko' != *MSIE* ]]
+ echo Pragma:no-cache
+ echo ''
+ eval 'cd "/isweb/www/ss/issapt/vmdb/data_downloads/power_export"; zip -rX - "flight_dependent_heater_data_443949.txt" "flight_dependent_data_443949.txt"'
+ cd /isweb/www/ss/issapt/vmdb/data_downloads/power_export
+ zip -rX - flight_dependent_heater_data_443949.txt flight_dependent_data_443949.txt
eval: zip: cannot execute [Exec format error]