I want to check the master process listening on ssh.sock is still alive.Currently I'm checking whether the exit code returned by ssh -S ssh.sock -O check <my-server> is zero, but I'm not sure if that's the correct way to handle this problem and I can't find any documentation. The master process is supposed to have ServerAliveInterval=20, so that it will die if the connection fails. Is there any case in which the return code would be non-zero, but the process itself would be alive?
How to understand output from ssh -O check in bash scripts?
ssh
The easy way to try is to initiate process (ssh -MS ssh.sock <my-server>), remove socket and try how will it behave. With working connection:$ ssh -S ssh.sock -O check <my-server>Master running (pid=24314)$ echo $?0When there is no socket, you will get something like this:$ ssh -S ssh.sock -O check <my-server>Control socket connect(ssh.sock): No such file or directory$echo $?255I believe handling the return code is the correct way.Is there any case in which the return code would be non-zero, but the process itself would be alive?As in the previous example, when the socket is removed for some reason, your connection is alive, but you can't check it from outside and you can't connect new sessions to it.