how to check whether the ssh tunnel is up
Damien Miller
djm at mindrot.org
Sat Apr 27 21:47:42 EST 2013
On Sat, 27 Apr 2013, Vincent Lin wrote:
> Hi damien,
>
> Thanks for your reply. ExitOnForwardFailure=yes will exit the process if SSH
> tunnel failed to create. But what if it's OK? Is there a way to know when
> it will be OK? I mean maybe it will cost some time, and when the tunnel is
> up, I can know it, or I can get the status all the time on the SSH client
> side, if it's possible. And what's the difference with or without -f, since
> I already create a SSH daemon. Do I have to fork another process again?
The fork will happen once the tunnel is ready, so you can do something
like:
ssh -nNfoExitOnForwardFailure=yes \
-oControlMaster=yes -oControlPath=~/.ssh/fwd%l-%r-%h-%p \
-L1234:10.11.12.13:1234 user at host
if test $? -ne 0 ; then
echo failed 2>&1
exit 1
fi
# ... later, to clean up:
ssh -O exit -oControlPath=~/.ssh/fwd%l-%r-%h-%p user at host
These use the multiplexing socket to cleanly terminate the forwarding ssh
client. Have a look at the sections on '-f' in ssh(1) and the various
options in ssh_config(5) to see how they work together.
-d
More information about the openssh-unix-dev
mailing list