Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get exit code of remote command through ssh

Tags:

linux

bash

ssh

I am running a script from remote machine via ssh:

ssh 'some_cmd;my_script'  

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

like image 906
Sudip Avatar asked Jun 08 '16 11:06

Sudip


1 Answers

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
like image 190
chepner Avatar answered Nov 15 '22 10:11

chepner