如何通过ssh获取远程命令的退出代码 [英] How to get exit code of remote command through ssh

查看:84
本文介绍了如何通过ssh获取远程命令的退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过ssh从远程计算机运行脚本:

I am running a script from remote machine via ssh:

ssh 'some_cmd;my_script'  

现在,我想在本地计算机上存储shell脚本的退出状态.我该怎么办?

Now, I want to store exit status of shell script on my local machine. How can I do it?

推荐答案

假定 ssh 本身没有问题,则其退出状态是在远程主机上执行的最后一条命令的退出状态.(如果发生错误,则退出状态为255.)

Assuming nothing goes wrong with ssh itself, its exit status is the exit status of the last command executed on the remote host. (If something does go wrong, its exit status is 255.)

$ ssh remotehost exit 13
$ echo $?
13

这篇关于如何通过ssh获取远程命令的退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆