【发布时间】: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