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?
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?
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 remotehost 'do something' ; retcode=$? and it's "stored" in $retcodessh itself have a problem, or did the program that ssh ran have one of those exit statuses?255 .... other than that a great answer :)ssh -V: OpenSSH_8.6p1, LibreSSL 3.3.6.I had same problem. I don't think the previous answers will work (at least, they did not work for me).
This is what worked for me: I ran my command and displayed the exit code and captured it in a variable.
Ensure you protect the $? sign with the escape sequence, \:
# retcode=$(ssh [email protected] "grep -q test /etc/passwd ; echo \$? " 2>/dev/null)
# echo $retcode
# 1