This is a bit of a long shot, but what would be the best way of getting ssh to, if a connection fails, run a command, and then retry to connect.
To share my use case, I am ssh-ing over an ssh tunnel to access a computer behind a firewall, meaning in my ~/.ssh/config is:
Host tunnel
HostName 192.168.1.27
Host target
HostName localhost
Port 2003
and in order for ssh target
to work, I would need to first have ssh -N -L 2003:localhost:22 tunnel
being executed in the background. I've resolved to doing this with a single command: screen -d -m ssh -N -L 2003:localhost:22 tunnel
.
It's not too annoying to run that command when ssh target
fails, but it would be nice if ssh could somehow automatically run it when the connection fails.