【问题标题】:AIX - bash scriptAIX - bash 脚本
【发布时间】:2014-02-22 23:18:52
【问题描述】:

我正在尝试在 AIX 中实现一个小型 bash 脚本,但遇到了一些问题。您可以在下面找到一个示例。我还有一个问题,如果我想将脚本添加到Crontab,我想我从IBM调用serverStatus.sh会有问题,如何避免这个问题。

#!/usr/bin/sh

WAS_HOME="/usr/IBM/WebSphere/AppServer/profiles/bpmnprd01/"

function StatusCheck()
{

$WAS_HOME/bin/serverStatus.sh BPM.AppTarget.bpmnprd01.0 -username admin -password admin
status=$(cat /usr/IBM/WebSphere/AppServer/profiles/bpmnprd01/logs/BPM.AppTarget.xxxxx/serverStatus.log| awk '{ if (NF > 0) { last = $NF } } END { print last }' "$@")
text="STOPPED"
if  [[ $text == $status ]]
    then
    echo "OK"
else
    echo "NOK"
fi
}

function start()
{
StatusCheck
}
start
-----------------------

当我尝试执行上面的脚本时,我收到以下错误:

[root@bpmnprd01]/root/health_check# ./servers_check.sh
./servers_check.sh[7]: 0403-057 Syntax error at line 7 : `(' is not expected.

...之后我在谷歌上搜索,我发现了一些在子程序中没有“()”的例子。但是我得到了这个:

[root@bpmnprd01]/root/health_check# ./servers_check.sh
./servers_check.sh[30]: 0403-057 Syntax error at line 33 : `StatusCheck' is not expected.

提前致谢 蒂亚戈

【问题讨论】:

    标签: bash websphere aix


    【解决方案1】:

    AIX 在 /bin/sh 中有一个真正的 bourne shell,不确定 /usr/bin/sh,但希望它也是 Bourne shell。

    将脚本标题行(#shebang!)更改为

     #!/usr/bin/bash
    

    或者which bash的结果

    IHTH

    【讨论】:

    • #!/usr/bin/sh 是正确的,问题是其他的,谢谢你的帮助。 -r-xr-xr-x 5 bin bin 292486 2012 年 3 月 27 日 sh
    • [root@bpmnprd01]/usr/bin# which sh /usr/bin/sh
    • 你为什么用bash标记你的问题和标题?真正的sh 无法处理$(...cmd substitions),如果必须使用#!/usr/bin/sh,则需要使用反引号cmd 替换。祝你好运。
    • 我做了一些更改,包括您的建议,我认为在函数调用中没有“()”的情况下从未尝试过,现在我收到此错误:ADMU0116I:: not found.
    • 你显然想寻求自己的解决方案来解决这个问题,祝你好运。
    【解决方案2】:

    您正在使用 bash 特定的语法,但使用 sh 调用脚本,这具有更多有限的功能。由于您想使用sh,您可以使用checkbashismsshellcheck 之类的工具来帮助发现不可移植的语法。

    直接的问题是 function foo() { ..; } 不是一个 POSIX 兼容的函数定义,您应该删除关键字 function 并只使用 foo() { ..; }

    您的 shell 也可能缺少[[ ]],在这种情况下,您应该使用[ ],而使用= 而不是==

    【讨论】:

    • 这是我现在的问题。我无法调用这个 WAS 系统脚本:/usr/IBM/WebSphere/AppServer/profiles/bpmnprd01/bin/serverStatus.sh BPM.AppTarget.xxxxx -username admin -password admin inside script
    • 问题出在 status=$(cat line is too long for VI :/
    猜你喜欢
    • 2015-01-17
    • 2019-08-29
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2019-11-06
    • 2012-02-22
    • 2016-03-14
    相关资源
    最近更新 更多