【问题标题】:shell: exit status of a method executing remotelyshell:远程执行的方法的退出状态
【发布时间】:2018-06-18 15:02:52
【问题描述】:

我有一个包含 2 种方法的脚本。一种方法在远程机器上执行命令,第二种方法相应地执行。

run_remote(){
sshpass -p $password ssh $user@$ipaddr /bin/bash << EOF
   if [ -e \$file ]; then
      echo "file exist"
      exit 1
   else
      echo "file doesnt exist"
   fi
EOF
   if [ check ]; then
      echo "failed"
      exit 1
   fi
}

run_local(){
   echo "run locally"
}

#main
run_remote
if [ $? == 0 ]; then
   run_local
fi

但即使文件存在与否,它总是执行run_local 方法。 如果有人能告诉我如何捕获一个方法在远程机器上执行时的退出状态,那将会很有帮助。

【问题讨论】:

    标签: shell methods ssh exit sshpass


    【解决方案1】:

    尝试在 echo "file doesn't exist" 行后面加上 exit 0

    【讨论】:

    • 感谢 rayrayray 回答问题。在 EOF 之后添加了一个代码,它正在停止脚本以发送正确的状态代码。我删除了该代码并且它起作用了。我也更新了问题,以免造成混淆。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-01
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    相关资源
    最近更新 更多