KSH shell 脚本 zip 命令无法正常工作:eval: zip: 无法执行

KSH shell 脚本 zip 命令无法正常工作:eval: zip: 无法执行

首先,我们的开发环境刚刚升级到 RHEL 7.5 (Maipo),我们之前使用的是 Oracle Solaris 10。一旦我们从 Solaris 切换到 Red Hat,这个问题就开始了。下面的 Korn shell 脚本在生产中可以正常工作,但仍在 Solaris 10 上。所以我假设这与该问题有关。正在压缩和下载的 zip 文件不会保存到 zip 文件夹中。当我打开桌面上刚刚下载的 zip 文件夹时,zip 文件夹是空的。

下图显示了文件列表。用户将为要下载的文件选中一个复选框,然后单击压缩和下载链接,它应该会压缩这些选定的文件并将其保存到您的桌面。不幸的是,zip 文件夹是空的。有什么想法可能是什么问题吗?

在此输入图像描述

这是下面被调用的 shell 脚本:

 1  #!/bin/ksh
 2  #
 3  # Utility to zip up files in the configuration_aerodynamic_properties area.
 4  # Script takes two arguments the directory and the file list.
 5  # The file list is tab seperated.
 6  # This script returns the zip file.
 7  #
 8  # $Log: vmdb_zip_files.sh,v $
 9  # Revision 1.4  2014/10/21 19:53:31  wmorris1
10  # ASR 13563 - Change incorrect mime type text/text to text/plain.
11  #
12  # Revision 1.3  2012/04/30 18:46:03  wmorris1
13  # ASR 12774 - Fix SSL and IE issue found after going to SSL.
14  #
15  # Revision 1.2  2004/11/11 12:49:33  bmorris
16  # ASR 55414 - removed UNIX groups for zipped file.
17  #
18  # Revision 1.1  2004/10/18 20:10:32  bmorris
19  # Initial revision
20  #
21  #set -x
22  #set -v
23  function error_message {
24    echo "Content-Type: text/plain;"
25    echo "Content-Disposition: attachment; filename=\"download_error.txt\";"
26    COMMAND="unix2dos "
27    echo ""
28    echo "$(${COMMAND}  <<-EOF
29  Error: $1
30
31  EOF
32  )"
33  }
34  if [ "$#" -lt 2 ]; then
35    error_message "Insufficient arguments to $(basename $0)!"
36    return 1
37  fi
38  CONTENT="application/x-zip-compressed"
39  # Parse the directory path.
40  # Internal Field Sep (IFS) empty, cause spaces in file names, directories are important
41  IFS=$""
42  FULL_DIRECTORY_PATH=$(echo "${1}" | tr -d '~\\')
43  # File lists are seperated by tabs, parse them
52  IFS=$(printf '\t')
53  set -A FILE_LIST ${2}
54  # Make each of the file parameters in the file list protected.
55  let count=0
56  while (( $count < ${#FILE_LIST[*]} )); do
57    FILE_LIST[count]="\"${FILE_LIST[count]}\""
58     let count="count +1"
59  done
60  # Reset the IFS to the default.
61  IFS=$(echo " \n\t")
62  if [[ -n $3 ]]; then
63    WEB_FILENAME="$3"
64  fi
65  # Don't let the user download stuff.
66  if [[ "${1}" = *..* ]] || [[ "${1}" = *~* ]] || [[ "${2}" = *..* ]] || [[ "${2}" = *~* ]]; then
67    error_message "Path ${1}/${2} violates security."
68    return 1
69  elif [[ ! -f ${FULL_DIRECTORY_PATH} ]] && [[ ! -d ${FULL_DIRECTORY_PATH} ]]; then
70    error_message "${FULL_FILE_PATH} does not exist or is not regular."
71    return 1
72  elif [[ ! -r ${FULL_DIRECTORY_PATH} ]]; then
73    error_message "${FULL_FILE_PATH} is not readable from the web."
74    return 1
75  fi
76  # Zip up the f
79  COMMAND="cd \"${FULL_DIRECTORY_PATH}\"; zip -rX - ${FILE_LIST[*]}"
82  echo "Content-Type: ${CONTENT};"
83  if [[ -z  $HTTP_USER_AGENT || $HTTP_USER_AGENT != *MSIE* ]]; then
84    # IE Can't handle ssl and zip files
85    echo "Pragma:no-cache"
86  fi
87
88  echo ""
98  eval "$COMMAND"

我使用 set -x 进行调试,这是来自服务器的错误日志:

 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]

不确定 zip 是通过包安装还是手动编译,我必须询问 sys ops,但这是/usr/bin/zip给我的文件的输出/usr/bin/zip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=747369bd1c41c4f8671a38f0055533a0c19a7769, stripped。至于命令uname -m给了我这个结果:x86_64

type 的输出为zipzip is a tracked alias for /oraloc/app/product/11.2.0/client_1/bin/zip并且 的输出file $(which zip)如下/oraloc/app/product/11.2.0/client_1/bin/zip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.4.0, not stripped

的输出echo $PATH如下:/isdev/isapps/vmdb/tools/apache-maven-3.3.9/bin:/isdev/isapps/vmdb/tools/apache-ant-1.9.7/bin:/isdev/isapps/vmdb/runlib/current:/oraloc/app/product/11.2.0/client_1/bin:/oraloc/app/product/11.2.0/client_1/OPatch:/tools/ileaf.ileaf/sun4os5/lib:/tools/ghostscript/current/bin/:/tools/hp2xx/bin/:/usr/lib/lp/postscript/:/tools/ileaf.ileaf/bin/::/tools/gmake/3_79_1/bin:/tools/rcs/current/bin/:/bin:/usr/j2se/bin/:/tools/gcc/3_0_3/bin:/isdev/isapps/vmdb/tools/bin:/homedev/isdev2/cmarti35/tools/java/bin:/usr/sfw/bin:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:/usr/bin/X11:/usr/bin/X11:/usr/dt/bin:/etc:/usr/etc:/opt/SUNWmotif/bin:/opt/SUNWspro/SC3.0/bin:/usr/ucb:/usr/sbin:/usr/ccs/bin:/tools/openssh/3.7.1p2/bin/:.:/usr/bin/X11

答案1

该命令type zip告诉您它将不会运行/usr/bin/zip,因此 的输出file /usr/bin/zip无关紧要。它正在使用 中的一个/oraloc/app/product/11.2.0/client_1/bin/,这是可疑的。

如果您/usr/bin/zip在脚本中使用 代替zip,它将修复它。

然而,从长远来看,问题是您的$PATH变量有很多优先考虑的特定于站点的内容(它首先尝试第一个目录,从左到右阅读)。该站点的某些特定内容配置错误。请参阅您的网站管理员。

答案2

ksh93 中有一个已知错误,当​​可执行文件完全没有问题时,该错误会导致此错误。 Solaris 10 使用这样古老的二进制文件,Korn Shell 是 ksh88(是的,1988 年),它没有这个错误。 Solaris 11 有 ksh93 并且确实有这个错误。 RHEL 当然使用 ksh93,因此存在错误,但 ISTR 他们对 RHEL7 有修复,Solaris 11 没有修复。

相关内容