【问题标题】:communication of two remote shell scripts through file通过文件通信两个远程shell脚本
【发布时间】:2013-01-03 20:44:44
【问题描述】:

我真的需要帮助来理解我的 shell 脚本的奇怪行为。

事实上,我有两个脚本在不同的节点上运行。第一个脚本 ssh 一个远程节点并启动第二个脚本。第二个脚本计算成本并将其发送到第一个脚本。对于第二个脚本,SSH 第一个脚本的节点(asker 节点)并将成本写入第一个脚本将读取的文件中(如下所示)。

问题是当 cost 的值为 0 时,第一个脚本继续正常执行,但如果它的值不同,则为 0,第一个脚本保持挂起并且不执行 ssh 之后的指令。

有人对此有解释吗? 如果需要,我可以提供有关我的代码的更多详细信息。

提前谢谢你。

第一个脚本:

....
ssh $remore_node "sh cost_computation.sh <parameters>"
cost=`cat $response_file`
if [ $cost -eq 0 ]
then
    ....
else
    ....
fi

第二个脚本(cost_computation):

....
computation of the cost 
ssh $asker_node "echo $cost > $response_file"

【问题讨论】:

    标签: file shell ssh communication


    【解决方案1】:

    你能做到吗?

    第一个脚本:

    ....
    cost=$(ssh $remore_node "sh cost_computation.sh <parameters>")
    if [ $cost -eq 0 ]
    then
        ....
    else
        ....
    fi
    

    第二个脚本(cost_computation):

    ....
    computation of the cost 
    echo $cost
    

    【讨论】:

    • 感谢您的回复。奇怪的是你的代码和我的一模一样。
    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 2016-01-21
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多