I want to check exit command is executed success in a ssh session.
My first attempt is using the command exit && echo $? || echo $?.The echo $? || echo $?,it should print 0 if exit successful.
The problem is echo never execute if exit execute success because connection is disconnected and the later command is lost.
My second attempt is splitting the command to two command, as this:
$ exit
$ echo $?
echo $? should be 0 if exit execute successful.
But another problem is echo $? maybe be swallowed because it send so quickly that arrived to the remote ssh host before exit be executed.
So, how to ensure exit is executed at remote host before send next command?
UPDATE
The using stage is I execute shell command at a program language and send message by a ssh pipe stream.So, I don't know the exit command executed time.If the exit command not completed, my follow commands will be swallowed because they send to the exiting host.
That is why I'm care about the exit command executed.