【问题标题】:Unexpected end of file - ksh文件意外结束 - ksh
【发布时间】:2014-12-02 17:31:25
【问题描述】:

我正在尝试执行一个调用 Oracle 产品中的作业的 ksh 脚本。当我运行/执行我的脚本时,我收到以下错误:

$ sh test.sh  
: command not found
: command not found
: command not found
: command not found
test.sh: line 31: syntax error: unexpected end of file
$

这是我的代码 - 请告诉我我做错了什么:

#!/usr/bin/ksh
#
#  OEDQJobSubmit.sh

export BatchKey="AVG"

# Environment details: CURRENT

export OEDQUser=user1
export OEDQPass=password
export OEDQPORT=8090
export OEDQHOST=`hostname`

if [ ${BatchKey} = "AVG" ]; then
   export Job="Job-Averages"
   export Project="IPVFB-AVG"
fi

cd /ora/mw_etl/Oracle_EDQ1/oracle.edq/
/ora/java/sunjdk/bin/java -jar jmxtools.jar runjob -job "${Job}" -project "${Project}" -u ${OEDQUser} -p ${OEDQPass} ${OEDQHOST}:${OEDQPORT}

export ReturnCode=${?}

if [ ${ReturnCode} == 0 ]; then
   exit 0
else
   exit 1
fi

谢谢!

【问题讨论】:

  • 为什么要将所有变量都放在环境中?您可能可以删除脚本中每次出现的“导出”一词,并且您应该了解这样做的含义。
  • 另外,最后 6 行(分配 ReturnCode,然后使用它指定要退出的参数)是完全多余的。脚本将退出并返回最后执行的命令的返回值。 (如果您真的关心将所有非零值映射到 1,只需执行 test $? = 0,但您可能并不真正关心这一点。)
  • 好吧,第一个 if 语句没有完成,这个脚本将为所有作业触发,我正在尝试对其进行测试,看看它是否适用于此刻。我的 BatchKey 目前也是硬编码的。这将被删除,并且在运行此脚本时,将传递一个参数。

标签: shell ksh


【解决方案1】:

你做错了,你用sh调用ksh脚本=)

2 个解决方案:

  • chmod +x test.sh; ./test.sh

  • ksh test.sh

【讨论】:

  • 如果我使用 ksh test.sh 我得到以下信息: $ ksh test.sh : not found [No such file or directory] ​​: not found [No such file or directory] ​​: not found [No这样的文件或目录]:找不到[没有这样的文件或目录] test.sh:第 14 行:第 31 行的语法错误:`if' 不匹配
  • 如果我使用 chmod +x test.sh; ./test.sh ..... 我得到以下信息: $ chmod +x test.sh; ./test.sh -ksh: ./test.sh: not found [No such file or directory]
  • 所以看起来复制和过去不起作用。我基本上用 linux 服务器上的 vi 编辑器重写了我的整个程序,并使用 ksh test.sh 运行它。有用。多谢你们。我之前做的是用 Notepad++ 编写程序并将 /past 复制到 linux。请注意,不要那样做
【解决方案2】:

您的文件包含回车符。

通过dos2unixtr -d '\r' 运行您的脚本。

【讨论】:

    猜你喜欢
    • 2012-06-10
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多