我有一个Korn Shell脚本,应该可以压缩文件,并且在开发中无法正常工作。相同的脚本可以在生产中使用,这很奇怪。我们最近在开发环境中将Solaris Unix盒升级为Linux盒。因此,我假设这可能是脚本无法执行的原因。
下面的图片显示了文件列表。用户将为要下载的文件选中一个复选框,然后单击“压缩并下载”链接,它应该将那些选定的文件压缩并保存到您的桌面。不幸的是,zip文件夹是空的。任何想法可能是什么问题?
这是下面压缩文件的代码。知道为什么这个Korn Shell脚本可以在开发中工作而不能在生产中工作吗?
#!/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我从-
中删除了set -A FILE_LIST -
,这是来自我们服务器的错误日志的结果。这是什么意思,因为我选择压缩并下载到桌面的txt文件仍未保存到zip文件夹中。以下是结果:
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]